Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova 3.0.0 - How to install a plugin

I'm totally new to app development and just started to make my first steps. I've installed Cordova and the needed utilities according this guide.

I've created my first app (using Cordova's create script) and I'm able to run it on my Nexus 4. Now I tried to install a plugin using plugman, and I'm stuck. This tutorial says I can install a plugin using

cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git

in the application directory. Two issues here: 1. In the application directory itself isn't a executable file named "cordova" 2. When I swtich to the cordova directory and execute the mentioned command, I get this error:

Cordova does not recognize the command plugin

Any ideas what I'm doing wrong? Or is ther a mistake in the tutorial? Thanks a lot for any help!

EDIT: I managed to install the plugins using plugman directly using

plugman install --platform android --project . --plugin https://git-wip-us.apache.org/repos/asf/cordova-plugin-geolocation.git

But nevertheless I'm still interested in how to install the plugins using cordova...

like image 675
user1619275 Avatar asked Sep 11 '13 10:09

user1619275


People also ask

Which command is used to install plugin in Cordova?

The cordova plugin add command requires you to specify the repository for the plugin code. Please note that when you follow the Web Project Dev workflow and use the CLI, the CLI will take care of adding the plugin code to the appropriate place for each platform.

How do I add a plugin to config xml Cordova?

When adding plugins or platforms, use the --save flag to add them to config. xml. Ex: cordova platform add android --save. Existing projects can use cordova plugin save and cordova platform save commands to save all previously installed plugins and platforms into your project's config.

Where is plugin xml in Cordova?

The plugin element is the plugin manifest's top-level element. The plugin namespace, http://apache.org/cordova/ns/plugins/1.0 . If the document contains XML from other namespaces, such as tags to be added to the AndroidManifest. xml file in the case of Android, those namespaces should also be included in the element.


2 Answers

Below are several ways I've used to install plugins from Cordova CLI, hope it helps:

Firstly, make sure you've installed cordova correctly(please refer to official document if needed):

cordova -v   // should print something like "3.5.0-0.2.6"
  1. Install from Cordova plugin registry

    cordova plugin add org.apache.cordova.device

    This should cover most cases and here is a list of plugins available in Cordova Plugin Registry.

  2. Install from a remote repository, typically from GitHub
    cordova plugin add https://github.com/brodysoft/Cordova-SQLitePlugin

    If you encountered something like "Error: Command failed: error: Failed connect to help.github.com:443; Connection refused while accessing", typically it's a proxy issue, you could retry after config your proxy:

    git config --global http.proxy http://user:password@proxy:xxx

    If it still not works, you could click "Dowload Zip" from github, unzip the downloaded file and then:

  3. Install from a local directory

    cordova plugin add /path/to/directory

    It will look in this directory and each of its subdirectories for the plugin.

like image 108
aqingsao Avatar answered Oct 10 '22 14:10

aqingsao


NOTE: this is related to Android platform of cordova 3.4 on my windows 8 machine (tested)

step 1=> Install plugman by command in cmd "npm install -g plugman" (note that you must have node installed)

step 2=> Download git from http://msysgit.github.com/ for windows (15 mb) install exe file

step 3=> create new variable in enviorment variable name = GIT_PATH and value= "C:\Program Files (x86)\Git (this is mine urs may be diff)", now append %GIT_PATH% in Path variable (very Important) check git command in cmd if no error than continue otherwise fix this now

step 4=> Now go to http://plugins.cordova.io/#/ find whatever plugin want to install. and get just this repository url like

step 5=> now whatever and anywhere project is, place following command in cmd

**plugman install --platform android --project F:\my17app\ --plugin https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git**

Step 7=> If it successfully install we can see in app/res/xml/config.xml file a new feature will be added with id of new plugin

PS: For environment variables see in control Panel=> System and Security => System =>Advanced System Security 
like image 37
Shailendra2014 Avatar answered Oct 10 '22 14:10

Shailendra2014