Installing Plugins with PhoneGap's Command-Line Interface

A few weeks ago I wrote about PhoneGap's Node.js command-line interface. A reader stopped by to check out the article and asked how to use the command-line interface to install plugins, which of course I had conveniently glossed over.

Well, PhoneGap 3.0 was released, and one of the big changes in version 3.0 was that a lot of the device functionality that used to ship with PhoneGap has been extracted to individual plugins. Having recently written about using InAppBrowser to build an OAuth login I figured I would update my OAuth example project for PhoneGap 3.0 and see how plugins work with the command-line interface.

First, I updated my package.json to use the latest cordova node module:

{
  "name": "google-api-oauth-phonegap",
  "version": "0.0.3",
  "dependencies": {
    "cordova": "~3.0.0"
  }
}

Then I ran npm update to update my project’s node modules.

At this point, I was all set up to develop with PhoneGap 3.0. However, since InAppBrowser is a plugin now, and I had not installed it yet, I wanted to see what would happen if I just ran the project without installing the plugin.

> cordova build ios
> cordova emulate ios

When I tested the app, the consent page opened just fine, but sure enough, when I got to the last step and tapped the Accept button, the button became disabled and the consent page did not disappear, which left me staring at this:

InAppBrowser not installed

So, as advertised, I had to install the InAppBrowser plugin to get my app working again:

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

I built the project and ran the emulator again, and this time the OAuth login worked!

As you can see, installing plugins with the command-line interface about as easy as it gets. You simply provide a URL (or path) to the plugin you want and the command-line interface takes care of the rest.

The only somewhat difficult part is discovering the correct plugin URL.

The plugin URLs for functionality like InAppBrowser that used to ship with PhoneGap can be found here. Most of the other community plugins are slowly being migrated out of the phonegap plugins GitHub repository, so it can sometimes be helpful to check there first to see if you can find a link to the 3.0-compatible plugin you want to use.

comments powered by Disqus