Platforms folder

I had a strange issue today with the project I am working on - I have fixed the issue but it worries me that I cannot be sure the problem won’t occur again.

The app I am working on uses the Push Notifications plugin (both Android and iOS). Suddenly, when testing the app today, I found that when an Android Push Notification was clicked on, the app would not launch. IOS was working fine.

I reverted my code to a previous commit (for a release that I knew for certain was working) and re-built the app. The problem was still there.

So I knew that it had to be some sort of build environment issue, even though by checking the commits between that release and my current build, nothing had changed that would related to platform/environment.

Eventually, after a great deal of head scratching, I removed the Android platform and re-added it again. After building the app again everything worked.

So how can I be sure that this doesn’t happen again? I’m pretty certain nothing had changed in that platform folder and yet removing and adding the platform fixed the issue.

Does anyone put their platform folder under source control? I never have done but I suppose if I had I may have seen something had changed?

I typically don’t source control that folder. rebuilding the platform folder is often my go-to solution whenever a plugin goes wonky.

1 Like

I don’t neither but sometimes I am thinking about it too. specially MyApp-Info.plist or project.properties

I always double check that my hooks worked correctly in case I remove/add the platform again

Side note: If I understood correctly, with Capacitor, this gonna be different and I will have to commit/push the platforms too.

What worries me is that without testing every feature of the app every time I build, how can I be sure the problem doesn’t occur again. It’s a real mystery to me (what might have caused it).

I would recommend checking in only the platforms.json file in that folder and using --save when installing plugins and always specifying an exact version when installing any plugin or platform. The rule I set for our dev teams after our first Ionic app was that all plugins and platforms must be added with specific version numbers. Not ~1.2.3 or ^1.2.3, just 1.2.3. That’s both for platform add and plugin add.

If you do that, both your config.xml and your platforms.json file will contain the exact same versions for cordova-andoird and cordova-ios, and exact versions of all your plugins.

If you do that, all your devs have to do is check out the project and run cordova prepare and they are gaurenteed to get all the exact same code you have. If you do not do those steps, they may very well install a different version of the Android plugin, iOS plugin, or any of the various other plugins your app might use (splash screen, push notifications, etc).

https://cordova.apache.org/docs/en/latest/platform_plugin_versioning_ref/

Edit: If you’re working alone this isn’t as big of a deal unless you switch machines or remove and reinstall a plugin or something. Idk if this is related to your exact issue, but to the general question of if you should commit the platforms folder, committing just platforms.json I believe is the correct thing to do.

2 Likes

@rloui thanks for that. I don’t have a platforms.json file in my platforms folder. Should that be automatically generated?

Ya, you should, unless something changed… I’m pretty sure I’m on the latest version of ionic though and I have it