I had much troubles using native plugins on Android (tested on fresh installs of 6.1.1 on Nexus 5 and 8.0.0 on Nexus 5x) because platform.ready() would not fire at any time. And using them outside of the callback would cause them to randomly work.
browsing forums I found 2 known solutions for this issue :
- reinstall dependencies, plugins and platform
- shorten app startup length
First I started a test project with only the plugin I needed (phonegap-plugin-push) and noticed that platform.ready() was firing just as supposed.
Then, back to my real project, I tried to uninstall all cordova plugins, disabling all none needed JS, deleting any external causes I could (for example, one of the font was still downloaded from the internet instead of being a local ressource), downgrading some npm dependencies to match the test project. Of course there were still a lot more of dependencies and at this point but I could not really do anything about it.
Still no platform.ready()
The problem occured even with --prod, which was fixing both cordova message “deviceready has not fired after 5 seconds” and ionic message “Ionic Native: deviceready did not fire within 5000ms. This can happen when plugins are in an inconsistent state. Try removing plugins from plugins/ and reinstalling them.”
Then I dug the Platform module and thru my IDE I found member functions that was not documented on (based on https://ionicframework.com/docs/api/platform/Platform/)
The one which did the trick was Platform.prepareReady()
Even without --prod, with cordova and ionic complaining that startup higher than 5 second, my console.log() wrapped in the platform ready would finally display.
So what is the deal with that function please ? It is not documented.
Even if that makes my plugin work, I’m kinda afraid that maybe I fire the ready manually even if the device is not really ready yet and I could cause bugs at the release time, on slower device for example.