Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add plugin to PhoneGap?

I'm confused a bit by PhoneGap documentation:

  • Link 1 // How add plugins using "phonegap local plugin add" command
  • Link 2 // Tutorial about how to use camera module
  • Link 3 // PhoneGap Plugins

    I've added camera module according (1). But in (2), there is information saying that I should add

    <plugin name="Capture" value="org.apache.cordova.Capture"/>
    

    to app/res/xml/plugins.xml and edit app/AndroidManifest.xml files too.

    In reference to 3), also there is information that <plugin ... /> construction is obsolete and the developer should use <gap:plugin ... />, instead.

  • like image 207
    ManFromSiberia Avatar asked Jul 29 '13 11:07

    ManFromSiberia


    People also ask

    How you can upgrade PhoneGap?

    For Android you just need to replace your . jar/. js files with the 1.2 versions and update the script tag to refer to the phonegap-1.2.


    2 Answers

    Referencing the latest API documentation:

    There are two ways to approach this, first is by using Plugman, and the other is by using CLI. The CLI approach is much simpler.

    The Plugman approach:

    1. First, Plugman must be installed. Plugman is the plugin manager used by PhoneGap 3.4. To install Plugman, use the Node JS CLI and enter:

      npm install -g plugman

    2. Install the specific plugin using the plugman install command. For example plugman install --platform android --project platforms/android --plugin org.apache.cordova.device-motion. Be sure that the parameter for the --project option points directly to the platform folder, e.g. for Android, that's where the AndroidManifest.xml file is. This command automatically adds all references to the plugins to the pertinent xml files.

    3. Be sure that your HTML file references phonegap.js by the line <script type="text/javascript" charset="utf-8" src="phonegap.js"></script>.

    Using CLI:

    1. Go to your app directory and enter the plugin command in the CLI. For example:

      phonegap plugin add org.apache.cordova.device-motion

      installs the accelerometer plugin.

    2. After the plugin has installed, it automatically updates all config.xml by adding the corresponding <feature> tags. Note that these updates only affect the platform-specific config.xml files. And so, the top-level config.xml file is not affected. You must manually copy and paste the <feature> tags to the top level config.xml. Otherwise, the plugins will be disabled when you run the app using phonegap run platform.

    Take note that the corresponding <feature> tags can only be added to the corresponding config.xml files if your project is already ready to deploy in that specific platform.

    like image 51
    brain56 Avatar answered Oct 11 '22 19:10

    brain56


    If you are using phonegap 3.0 the latest as of this answer, you add plugins from the command line like so.

    "phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-media-capture.git"

    This is supposed to then add all the references to the plugin automatically now.

    like image 23
    Damon Hogan Avatar answered Oct 11 '22 18:10

    Damon Hogan