Assumptions: You have phonegap installed and have used basic Phonegap CLI commands. You have already build simple first Phonegap app
Plugins are created specific to each mobile platform basis, which means not all plugins support all the platforms. However, most of the popular plugins support iOS and Android. All the Cordova plugins that are managed by the Apache Foundation support all three major mobile platforms: iOS, Android, and Windows.
Starting with V 3.0, API access to the native features is separated from the core PhoneGap by plugins. This means that PhoneGap doesn’t provide any plugin installed by default and they need to be managed using command-line interface (CLI), Git repository, plugman, or npm, the new upcoming standard for plugins.
When you create a new PhoneGap project, it does not have any plugins present. This is the new default behaviour. Any plugins that you need, even the core plugins, must be explicitly added.
There are hundreds of plugins that take care of most of the native features, and if there is any missing, Phonegap also allows you to create these plugins.
Let’s look at three ways to manage plugins for the application.
– Cross-platform workflow: The PhoneGap’s command-line interface (CLI) tool is used to add plugins, which enables you to manage multiple mobile platforms at the same time
– Platform-centered workflow: The Plugman’s CLI tool is on a lower level and is used to manage each mobile platform separately
– Github Repositories through CLI: Easy to use through the CLI, you can install and manage plugins from their Github repos.
The plugins that are available in the search are residing in the Cordova Plugin Registry service and are identified by the plugin ID. So let’s look at how to Search the Plugin by keyword first.
(Note: All the commands except creating a new project should be run in the working directory for a project).
phonegap plugin search
Once you see the plugin that fits the needs of your app, it can be installed with a simple command. Every plugin is identified by the plugin ID, which you can see from the result:
phonegap plugin add
Besides adding plugins by the plugin ID, plugins can be added from the remote Git repository as well, typically a GitHub repository:
phonegap plugin add
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-camera.git
You can simply add a plugin from the local directory as well. This is suitable if you are developing your own plugin or downloading a source for the plugin:
phonegap plugin add
It is simple to list all the currently installed plugins for the application, just by running the following command:
phonegap plugin ls
This will show all the currently installed plugins. Specific to our example, it will return the previously installed plugin.
Often we also need to remove extra or unnecessary plugins or plugins that may be unstable. How to do so using the CLI.
phonegap plugin rm
Installing Plugman & Using it
Plugman is a utility to help plugin management in Cordova / Phonegap. The prerequisites to install the Plugman utility are Node.js and git. If you have followed the instructions on how to install PhoneGap, then you only need to install the Plugman utility with the following command:
npm install -g plugman
You can search for the existing plugins from the same plugin repository with the following command:
. This searches in http://registry.cordova.io which the official cordova plugin repository
Installing Plugins with Plugman
$ plugman install --platform --project --plugin [--plugins_dir ] [--www ] [--variable = [--variable = ...]]
Let’s look at the various options provided here:
name: The directory name where the plugin contents exist. This must be an existing directory under the –plugins_dir path (see below for more info) or a plugin in the Cordova registry.
url: A URL starting with https:// or git://, pointing to a valid git repository that is clonable and contains a plugin.xml file. The contents of this repository would be copied into the –plugins_dir.
path: A path to a directory containing a valid plugin which includes a plugin.xml file. This path’s contents will be copied into the –plugins_dir.
–plugins_dir: defaults to
–www: defaults to the project’s www folder location, but can be any directory that is to be used as cordova project application web assets.
–variable: allows to specify certain variables at install time, necessary for certain plugins requiring API keys or other custom, user-defined parameters. Please see the plugin specification for more information.
Removing Plugins with Plugman
plugman uninstall —platform —plugin
That’s a quick look at using the CLI and Plugman utility for plugin management in PhoneGap. We’ll shortly look at how to use npm for the same and also few of the latest plugins for PhoneGap. However if you’re simply looking for Mobile App Development from Delhi,India ; just check our relevant web pages.