How to develop custom Cordova plugin

So you wanted to develop a custom cordova plugin. At this point i am guessing already you have installed NodeJS, NPM, Cordova and Android SDK/xCode.

To start with the cordova plugin development, there is a great tool, which is also suggested by Apache Cordova to manage Cordova plugins. So that great tool name is plugman. You can execute this command from the command prompt/terminal.

npm install plugman -g

After installing the plugman, go to terminal and execute the following command to create a hello world plugin

plugman create -name MyHello --plugin_id --plugin_version 0.0.1
plugman platform add --platform_name android

By this time, in your working directory already a folder has been created with name as “MyHello”.

In the same way you can enable for plugin for iOS. Using following command you can add the iOS support for the custom newly created plugin.

plugman platform add --platform_name ios

Now to use this plugin. OK to use this plugin you have 2 option

  • Publish the plugin in NPM
  • Directly use this folder/plugin to your cordova application

Let’s add the plugin using command prompt. Just imagine you have kept the plugin in c:/myPlugin. So you need to use following command to add the plugin to your cordova project.

cordova plugin add c:/myPlugin