简体   繁体   中英

Cordova Plugins not getting picked up after grunt build to .apk

Im creating a hybrid mobile app using cordova .

I add the cordova-contacts and cordova-calendar plugins to the project and these are getting reflected in the android.json and the features are being listed under platforms/android/res/xml/config.xml .

I build the apk using

grunt build --platform=android

After i get the android-debug.apk on decompiling , I find that the Manifest file contains all the read and write permissions and the plugins seem to be present.

But in the js viewModels of the hybrid app, the plugins are not being found .

Error : Undefined

var options = new ContactFindOptions()

Steps followed :

In the cordova project ,

cordova plugin add cordova-plugin-contacts

Verified that the changes are seen in config and .json files .

Is there any linkage steps which I have missed ? Is it necessary that the cordova plugins be available in the Gruntfile.js ?

UPDATE : Cordova plugin versions ::

cordova-plugin-calendar:4.5.5, cordova-plugin-contacts:2.2.1

On browsing some more , have found that certain versions of the plugin were pointing to incorrect js files. Is it the same case here ?

You can check plugins being installed or not from command line by firing below command inside app folder.

cordova plugin ls

That way you will know what all plugins are installed.

In case your plugin is listed. Then I think issue can be android platform compatibility with plugin. (Android 6+ has permission updates that had lead to incompatible plugins)

You can try removing platform by below command.

cordova platform rm android

And then add it again by below command

cordova platform add android

Note: Once you remove your platform you will loose assets (icons and splash screen images & any other platform related fixes done inside platform\\android folder). So copy those files before removing android platform.

By removing and adding android platform, cordova will reinstall plugins and that might fix your incompatible plugin issue.

The packaging done by grunt to create an apk is such that , when the app is installed and deployed on a device , cordova.js is injected into the base html page.

Then inside cordova.js we find the getPathPrefixMethod() which is recursing through all the script tags to find cordova.js . This path prefix is used for finding the cordova_plugins.js as well.

If we add explicit cordova.js script tags , our plugins will most likely not get picked up.

During debugging with emulator and chrome , noticed the issue.

Hope this helps. Thanks .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM