phonegap-pluginscordova-pluginsphonegap-buildphonegap-cliphonegap-desktop-app

how to use cordova plugins with phonegap cli


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


Solution

  • 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.