Adding Cordova (Phonegap) Plugins manually to existing android projects

自作多情 提交于 2019-12-04 15:00:44

It is possible to add plugins manually, and that is how we did it in the old days before the Cordova/Phonegap CLI or PlugMan

options

A. use PlugMan directly

npm install -g plugman

check out the plugman documentation. Outside of a Cordova project, plugman is your best bet for a clean automated install

B. manually

  1. add the .java files to the android project src/ directory remember their path has to match their namespace

  2. dump the plugin js file somewhere in assets/www/*

  3. add a feature tag to platform config.xml

It has been a long time since I added a plugin manually, and the cordova plugin spec has gone through major changes multiple times since then. You may need to manually include the plugin js implementation (eg via script tags in index.html)

I would highly recommend you use PlugMan, or at least try before the manual install.

Seems you're using eclipse.

A cordova 3.x project looks like this :

/www
/plugins
/platforms
/platforms/android
/platforms/android/assets/www
...

When you run cordova plugin add https://theurlwhichworks.org/ the plugin is added only in the /plugins folder but not in your platform folder.

In your eclipse project you only see /platforms/android folder.

To actually add the plugin to the android platform, you have to build the platform :

cordova build android

or at least prepare the platform (same as build but does not try to compile):

cordova prepare android

But be aware that when you either build or prepare, the content of the platform/android/assets/www folder will be replaced with the content of the root www folder.

So if you've been modifying directly the assets/www folder in eclipse, DO NOT FORGET TO SAVE IT BEFORE YOU BUILD OR PREPARE!!!

Every time plugins start acting funny for me I usually remove and re-add the platform and everything usually sorts itself out. The commands for Android for example,

cordova platform remove android

cordova platform add android

If your plugin list has what you expect, re-adding the platform re-downloads all the plugins.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!