Custom Cordova Plugins
Last updated
Was this helpful?
Last updated
Was this helpful?
Cordova Plugin provides a simple way to write a native code onto your program. On this page, we will describe how to create and add custom Cordova plugins into your Monaca project.
Your custom Cordova plugin needs to follow these requirements:
It should be compatible with Cordova 4.2 or higher.
It must have a plugin.xml
file and is installable with plugman
command line tool.
It must support iOS and Android platforms.
You can find various Cordova plugins in the Internet, but it is likely that they are either obsolete or their version would not match. Therefore, how to create a custom Cordova plugin from scratch is covered in this page.
A typical structure of a Cordova plugin is as follows (directories are displayed in bold letters):
plugin_name
src
ios
plugin_name.h
plugin_name.h
www
plugin_name.js
plugin.xml
Before getting started, please download the following zip file containing sample plugin code.
When you extract the package, you will see the following files and folders:
Below is a plugin.xml
file from the downloaded sample plugin.
hello_world.js
is defined as js-module
in plugin spec. Therefore, it will be automatically loaded by cordova.js
, which is included in loader.js
.
Native code must be written in either Objective-C or Java, depending on the platform. It must have the same function as defined in the JavaScript file. Also, please be aware that all callbacks are asynchronous.
Here are the guides about native code development.
To import a custom Cordova plugin, please do as follows:
From the Monaca Cloud IDE, go to Configure → Cordova plugin Settings.
The Cordova Plugins page will be shown. Click the Import Cordova Plugin button.
3. Then, browse your plugin file (zip file) and click OK.
Custom built Monaca Debugger is a debugger which is built within Monaca Cloud IDE inside a project containing custom or external third-party Cordova plugins. Please refer to the following links on how to build custom built debugger and the differences between the standard and custom built debugger:
Please make sure to import the custom or external third-party Cordova plugins before building the custom built debugger.
Create a project in the Monaca Cloud IDE using the Minimum Project Template
.
Add the following snippet in the index.html
file. The code below shows just a simple message dialog using the sample custom Cordova plugin:
Now, run the project in the standard Monaca Debugger. You will see that the message dialog will not be shown because the custom Cordova plugin doesn't exist in the standard debugger.
Build a custom built Monaca Debugger. Please refer to the following links on how to build a custom built Monaca Debugger:
Install the custom built Monaca Debugger.
Open the debugger and check the debugger's information by clicking the About this debugger button.
You should be able to find the custom Cordova plugin as shown in the screenshot below:
Login to the debugger and run the project containing the custom Cordova plugin. The message dialog should show if the project runs properly.
plugin.xml
file is a plugin specification file containing plugin's definitions. For more details, please refer to .
For more details about how to write Cordova callback function, please refer to .
The standard Monaca Debugger, which can be found in the store such as App Store or Google Play, includes the standard (core) and several third-party Cordova plugins (refer to for the list of all third-party Cordova plugins pre-included in Monaca). For this reason, the standard Monaca Debugger cannot be used with Monaca projects containing custom or other external third-party Cordova plugins. In this case, custom built Monaca Debugger is required to run such projects properly.
We also offer technical support (fee required) for developing your custom Cordova Plugin. Please contact our support team .
Import a sample custom Cordova plugin you downloaded earlier in .