Random thoughts & observations

From the mundane to the profound and everything in between here’s what’s rocking our world

Managing Cordova PhoneGap plugins from the command line

Posted: November 13, 2015
Written by: Saints At Play
Category: PhoneGap

In the following mini-tutorial we'll look at how easy it is to add, find, list and remove plugins for Cordova PhoneGap projects using the command line.

We are going to assume that you have the following software installed on your system:

It's also assumed that you have some familiarity with using the command line.

If you can answer yes to all of the above let's get started!

Installing plugins

Cordova PhoneGap 3 brought with it not only the command line but also a new way of adding plugins to your projects.

A plugin is a piece of code designed to interface with native device functionality such as vibration, taking photos and connecting to a network for example.

By default all plugins, even core plugins, have to be manually added to a Cordova project by the developer - but this is not as difficult as it initially sounds.

Using the command line navigate to your project directory and install plugins with the following command:

cordova plugin add name_of_plugin_here

Relatively painless right?

Finding plugins

As Cordova plugins are able to be added to a project from online repositories using the command line it would make sense that we should be able to search these repositories right?

Piece of cake.

If, for example, we wanted to find all repository plugins for adding purchase functionality to our App we would, in the root of our project, use the search command like so:

cordova plugin search purchase

Which, at the present time of writing, would return the following results:

cc.fovea.cordova.purchase - 
         Cordova Purchase plugin for iOS and Android (AppStore and PlayStore)
cc.fovea.plugins.inapppurchase - 
         In app purchase support for iOS
cc.mahendra.cordova.purchase - 
         Cordova Purchase plugin for iOS and Android (AppStore and PlayStore)
cn.10086.iapsdk - 
         add China Mobile In-App Purchase SDK to cordova project, as dependency 
         of other plugins
com.google.payments - 
         Enable in-app-purchases in the App Store and Play Store using a mobile 
         version of the Google Wallet for Digital Goods API
  
com.ludei.inapps.android.amazon - 
         Amazon In-App Purchase implementation
com.ludei.inapps.android.common - 
         Cross platform In-App Purchase API for different stores. Full support 
         for banners and interstitials. 
         Built-in local and server-side receipt validation, secure consumable 
         and non-consumable purchase tracking, local products cache and more
com.ludei.inapps.android.googleplay - 
         Android Google Play In-App Purchase implementation
com.ludei.inapps.common - 
         Cocoon InApps API
com.ludei.inapps.ios.appstore - 
         iOS In-App Purchase API
com.mediamatrixdoo.amazoniap - 
        Amazon In App Purchasing implementation for Cordova / PhoneGap. 
        By using this Cordova plugin within your app, you enable your customers 
        to use 1-Click ordering to purchase items from Amazon. The plugin will 
        work with Cordova / PhoneGap >= 3.0. It completely wraps Amazon IAP 
        v2.0 API so you can offer consumables, entitlements, or subscriptions in 
        your app.
    
com.mikha.inapp - 
        Cordova Purchase plugin for iOS and Android (AppStore and PlayStore)
com.mohamnag.inappbilling - 
        This plugin targets in app purchasing for PlayStore in-app billing 
        API v3 and StoreKit on iOS >= 7 providing a unified JavaScript 
        interface in order to make it possible having one JavaScript code which 
        works with both stores.

        Refer to wiki (https://github.com/mohamnag/InAppBilling/wiki) for 
        introduction and instructions on using this plugin.
    
com.rjfun.cordova.plugin.appleiap - 
        Add Apple In-App Purchase support (iOS only)
com.rjfun.cordova.plugin.paypalmpl - 
        Add PayPal support with MPL SDK (Mobile Payment Library, not new SDK) to 
        your cordova apps or games
de.4brains.cordova.purchase - 
        Cordova Purchase plugin for iOS and Android (AppStore and PlayStore)
jp.wizcorp.phonegap.plugin.wizpurchase - 
        This plugin allows payments to be made on Android and iOS.

That's a pretty extensive set of results!

For further repositories connected to the Cordova PhoneGap ecosystem you can visit the following websites:

  • Cordova Plugins - Official Cordova plugins registry
  • ngCordova - A repository of AngularJS plugins built on top of the Cordova API
  • Plugreg - A plugin registry for all Cordova/PhoneGap plugins

Listing plugins

To find which plugins are currently installed in your project simply type out the following command:

cordova plugin list

// Or the shorthand version
cordova plugin ls

Which will output a full list of installed plugins like so:

cordova-plugin-battery-status 1.1.0 "Battery"
cordova-plugin-console 1.0.1 "Console"
cordova-plugin-device 1.0.1 "Device"
cordova-plugin-device-motion 1.1.1 "Device Motion"
cordova-plugin-device-orientation 1.0.1 "Device Orientation"
cordova-plugin-dialogs 1.1.1 "Notification"
cordova-plugin-file 3.0.0 "File"
cordova-plugin-file-transfer 1.3.0 "File Transfer"
cordova-plugin-geolocation 1.0.1 "Geolocation"
cordova-plugin-globalization 1.0.1 "Globalization"
cordova-plugin-media 1.0.1 "Media"
cordova-plugin-media-capture 1.0.1 "Capture"
cordova-plugin-network-information 1.0.1 "Network Information"
cordova-plugin-splashscreen 2.1.0 "Splashscreen"
cordova-plugin-whitelist 1.0.0 "Whitelist"
ionic-plugin-keyboard 1.0.7 "Keyboard"

Removing plugins

To remove a plugin from your project simply refer to it by the same identifier shown in the output from the list command. If, for example, we wanted to remove the File Transfer plugin we would issue the following command:

cordova plugin remove cordova-plugin-file-transfer

// Or the shorthand version
cordova plugin rm cordova-plugin-file-transfer

And, depending on what platforms we have installed for our Cordova PhoneGap project, we would see output akin to the following:

Uninstalling cordova-plugin-file-transfer from android
Uninstalling cordova-plugin-file-transfer from ios
Removing "cordova-plugin-file-transfer"

Wrapping it up

Thanks to the Cordova application framework and a host of contributions from incredible developer talent all over the world we can add functionality to our projects quickly and easily through a plugin architecture that requires nothing more taxing than a few keystrokes from the command line.

« Return to Posts

Comments

There are no comments

Posting comments after three months has been disabled.