Adding Cordova (Phonegap) Plugins manually to existing android projects
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
add the .java files to the android project src/ directory remember their path has to match their namespace
dump the plugin js file somewhere in assets/www/*
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.
Dan
Updated on June 27, 2022Comments
-
Dan almost 2 years
I'm trying to add additional Phonegap plugins (namely, the File plugin) to an existing android application that uses Phonegap.
I've tried navigating to my project directory (in my workspace) and then run the command
cordova plugin add https://theurlwhichworks.org/
It says the plugin is installing, and when I go to look in my workspace on my computer, there is a folder titled plugins, and inside, a directory called
org.apache.cordova.file
which means that the plugin (apparently) downloaded correctly, but doesn't seem to have been added to my project.
Is there any way to manually add this plugin (or others) to my android project directly? I build+run my application to an attached device from eclipse, because anytime I try to use the CLI with regard to cordova/phonegap I always seem to be doing something wrong, or the result is not at all what I expected.
Hopefully it is possible to add these plugins manually. I appreciate any suggestions
-
Dan almost 10 yearsThank you very much for such a detailed response - I had not heard of PlugMan before now, but that might be a good route to explore!
-
Lorenzo almost 10 yearsmy pleasure @Dan. PlugMan is a node module written by the same team as Cordova and Cordova CLI, and it is a better option when you just want to manage a single platform. The Cordova CLI is better when you need to manage multiple platforms from a single project. Oh, and accept my answer if it works out!
-
Dan over 9 yearsthis definitely helped it make sense to me- but just to clarify your last statement in bold: does that mean if I have an android application already and I attempt to add a plugin to that application, i'll lose anything I already have in my assets folder? Thank you!
-
QuickFix over 9 yearsThe assets/www folder will be overwritten with the root www folder. The normal process is to work in the root www folder and let the CLI manage what's in the platform folder. The advantage is you can use any js editor instead of eclipse (which I find crappy for js). If you have only one platform and want to work in eclipse, then you should keep only the platform/android folder of your project and use plugman to manage plugins as suggested by Lorenzo.
-
firepol about 8 yearsHi there, I have cordova 6, I tried plugman, it seems to install a plugin for ios correctly, e.g. I see in ios/www/cordova_plugins.js the proper exports. Some files were also copied in www. But asap I run cordova run ios --device, the www folder is emptied and also the cordova_plugins.js is reset to default. I miss something or plugman is not really useful like that... help appreciated.
-
Jules over 6 yearsTrying to use
plugman
to install a plugin, I get the following error message:Cannot read property 'fail' of undefined
. Any ideas why this isn't working? -
Lorenzo over 6 yearsHey Jules, didn't want to leave you hanging, but it has been some time since I have been directly involved in the Cordova/Phonegap project. I would imagine that things have changed a lot in the last 4 years, and I don't know about the current toolchain. I would recommend posting a fresh question, or contacting the Cordova Apache Project directly. They are extremely helpful through the mailing list.