how to use cordova plugins with phonegap cli - phonegap-plugins

I am new to phonegap and want to install try install a plugin. There are many websites explaining to use command cordova plugin add <plugin name> .When I type this its shows cordova is not recognized as command . This may be because I have installed Phonegap cli through npm install -g phonegap.
So now whenever I try to add a cordova plugin its showing not a command. Is that I can use only plugins made specifically for phonegap. I know that in phonegap build I only need to add a line in config.xml but what if I want to use plugin made for cordova? how to add it into config.xml? Even when I click on a specific plugin on the page http://docs.phonegap.com/references/plugin-apis/ it takes me to correspoding github page which shows to install it using cordova plugin add command.
Thank You

Like johnborges said, for most (but not all) commands, you can simply substitute cordova with phonegap, so the command for adding a plugin becomes:
phonegap plugin add <plugin_name>
As for your question about PhoneGap Build, use the following syntax with version 5 or later:
<plugin name="..." spec="..." />
Where the name is the public name of the plugin, and spec is the version of the plugin that you want to add. The spec is optional and if you omit it, the latest version will be used. It is recommended to always specify the version. Here are examples of how to add some popular plugins:
<plugin name="cordova-plugin-inappbrowser" spec="1.3.0" />
<plugin name="cordova-plugin-device" spec="1.1.2" />
<plugin name="cordova-plugin-splashscreen" spec="3.2.2" />
As you can see in these examples, you can use Cordova plugins with PhoneGap Build. In fact, PhoneGap Build plugins have been discontinued, so you have to use Cordova plugins.

Read this for a better understanding on the difference between Cordova and PhoneGap.
As for the plugin you're trying to install, all Cordova Plugins work with the PhoneGap CLI you're using. Regardless of what the documentation says, just substitute cordova with phonegap in you're case.
phonegap plugin add <plugin_name> --save
The --save option will automatically add it to your config.xml.
.

Related

Unable to add plugins to cordova project. npm error?

I have a Cordova application and want to add a plugin to my Cordova project. It worked yesterday!
What I did:
Updated Android Studio to 3.x
Updated Cordova
If I want use the cordova add command, I get this error:
What should I do?
Hard Reset it: Try to remove that plugin you installed yesterday, maybe do a clean install of Cordova or update all dependencies and add missing through Gradle and then finally go for installing the plugins. Somehow, I feel that Cordova version or some dependency mismatch is giving birth to such problems.

Getting error while Installing Cordova plugin

I am trying to add this plugin to my app: https://www.npmjs.com/package/cordova-pdf-generator
I installed NPM as instructed in https://blog.teamtreehouse.com/install-node-js-npm-windows. Then opened command prompt window and went to my app's folder. later i ran below commands in command prompt "npm install cordova-pdf-generator".After that ran this: "cordova plugins add node_modules/cordova-pdf-generator"
While running cordova plugins add node_modules/cordova-pdf-generator i am getting cordova.js script error.Please help me!!
Thanks,
Raghu
Those instructions seem... odd. After installing npm, you should only need to make a call to:
cordova plugin add cordova-pdf-generator --save
This should install the plugin from npm to your app, and add a line to your config.xml with the plugin info.
EDIT: thinking about the npm stuff some more, it looks like the author did some weird stuff to archive it. So... here's one way to get the plugin working. You've probably already called:
npm install cordova-pdf-generator
So that means you should have a subdirectory of the current directory named node_modules. The next steps you need to take:
Create a cordova project:
cordova create MyProject
Add the plugin to the project:
cd MyProject
cordova plugins add ../node_modules/cordova-pdf-generator
The creating of the project was needed for the plugin to be added to it. That step doesn't appear to be listed in the cordova-pdf-generator project on npmjs.com.

How to add cordova plugins now that they are renamed and ported to npm?

For example, I want to add the camera and file Cordova plugin. According to the official documentation, I should do
meteor add cordova:org.apache.cordova.camera#0.3.1
However, the plugin has been renamed cordova-plugin-camera, how can I add the newest compatible version? I know I need to use 0.3.1 because the documentation said that. But how do I know which version to use for the cordova-plugin-file?
Meteor will support new cordova npm plugin registry in next release.
For time being, you could add the latest camera plugin from github tarball:
meteor add cordova:cordova-plugin-camera#https://github.com/apache/cordova-plugin-camera/tarball/437cf3d93a2c0c841d38c6c80472b2ba118f372a

How to update sencha cordova version

Trying to build a sencha project with:
sencha app refresh
sencha app build package
It is usually built on another machine that's unavailable right now.
I can see one of the things that has changed is in cordova.js: from:
CORDOVA_JS_BUILD_LABEL = 3.3.0 to:
CORDOVA_JS_BUILD_LABEL = 3.0.0-0-ge670de9
So this newer build machine is on an outdated version of cordova it appears.
So I ran npm install cordova -g to update it.
But it builds the same. What needs updating and how do I do this?
With npm you update the cordova binaries, but not the existing Cordova projects. In order to update the iOS/Android/WP/... projects, go into your main cordova project folder (in your case, the cordova folder inside your Sencha app) and execute:
cordova platform update ios
Replace ios for the platform you want to update. If you have several target plaforms, run the command once for each one.
I would recommend you to update all the plugins after the upgrade. For that, run:
cordova plugin list
in the same folder as before, and do a
cordova plugin remove plugin_name
cordova plugin add plugin_name
for each plugin that you are currently using.

Cordova inAppBrowser plugin issue on windows

so I've been trying to add this plugin with command
cordova plugin add
https://git-wip-us.apache.org/repos/asf/cordova-plugin-inappbrowser.git
which worked on MAC and Linux after
npm update -g cordova
but on windows I'm still getting
cannot read property 'install' of undefined
Moreover - when I'm trying to uninstall ( cordova plugin rm org.apache.cordova.inappbrowser ) then I'm getting
cannot read property 'uninstall' of undefined
Weird thing is that I have two cordova folders - one in
C:\Users\me\AppData\Roaming\npm\node_modules and the second one in
C:\Users\me\AppData\Roaming\npm\node_modules\phonegap\node_modules . Path which I added to my environmental variables is C:\Users\mati\AppData\Roaming\npm\node_modules\phonegap\node_modules\.bin
I think that this is the problem reported about a week ago as CB-6008 on the Cordova bug tracker.
It may be a symptom of having an out-of-date cordova installation still. The issue there was solved by removing and reinstalling Cordova to ensure that the latest version was in use.
Delete the content of your platforms and plugins folder. re-install your plugins and the problem should be gone. In my case the following command
phonegap local plugin add org.apache.cordova.inappbrowser
produced -> [error] Cannot read property 'install' of undefined
and the above procedure fixed it.
Have you added a platform to your cordova project (before trying to add a plugin)?
npm update -g cordova
cordova create myproject
cd myproject
cordova platform add android
cordova plugin add _
I think the undefined error means a dependency of the add plugin command is not there.
For me, the solution was to update plugman module:
npm install -g plugman

Resources