Intel XDK supports Cordova plugins.You can use Cordova plugins in your app.Perhaps it is the most basic task you have to perform while creating an app using Intel XDK.In this post I will provide step by step details to add Cordova plugin into your app.
Open Project listing page
I assume you have installed and launched Intel XDK.After launching Intel XDK you have created a new project.If not then you can read create first mobile app with Intel XDK.The tutorial is aimed for new users.It will give you idea of Intel XDK IDE.After creating the project you can click on Projects option situated at top left.
That will display list of open projects.The displayed screen will look as shown in the image below.You can click on the project to which you want to add the plugin.
Adding Official Cordova plugins
On the project listing under Cordova hybrid mobile app setting you can see Plugin option.If you click on the Plugin drop down option you can see Included plugins and Third party plugins.The included plugin section is divided into two sections Standard Cordova plugins and Featured and Custom cordova plugins.Adding these plugins are simple task.You just need to click the checkbox.
If you want to remove any plugin then you can uncheck the plugin.There is no other action required from your side.All the necessary files are included within your app code.You just need to start making the code changes.Next we will see how to add the third party plugins.
Adding third party Cordova plugins
The number of third party plugins for Cordova is huge.They really make Phonegap or Cordova so powerful.Most of them are open source and hosted on Github.You can search for a Cordova plugin at this link.To add a third party cordova plugin to your app follow the step mentioned below
Click on the third party plugin option.You will see two buttons Import local plugin and Get plugin from the web.I would recommend using Get plugin from the web option.Import local plugin option needs you to download the plugin first.That method is good if you want to use same plugin on multiple apps.That way you need to download the plugin once.
Lets first discuss about adding the plugin from the web.To add the plugin from web click on get plugin from the web button.After clicking on that button below pop up screen is displayed to you.
On the displayed screen you need to enter below information
- Name – Add the name for the plugin.You can use any meaningful name.If you add multiple third party plugin make sure the names are unique.For example if you add Admob plugin then you can name it as AdmobPlug or anything you like
- Plugin ID – Open the Github URL of the plugin in a browser.After opening the github URL look for plugin.xml file.It is generally on the main page itself.Click on the plugin.xml file.It will open the file in browser.
Look for id= in the file.Copy the text you have with in the quotes after id= text.This is unique identifier for the plugin.Copy the unique identifier and paste into the plugin ID field for Intel XDK.
- Now if the plugin is located in Apache Cordova plugins registry then you can check the box.That way Intel XDK will automatically include the plugin in your app.You can keep the Repo URL blank.
- This step is required if the plugin is not in Apache Cordova plugins registry.You need to paste the Github repo URL in this field.
- Now click on the Import button.
If you want to add the plugin from local then after downloading the plugin zip file extract it in a folder.The Name and Plugin ID things mentioned above are same in this case as well.The only difference is in third part.In this case you do not have to mention Repo URL.You have to browse to folder you have extracted the plugin.After that you can click on the Import button.
If you followed the steps mentioned above Intel XDK will automatically add the plugin to your app.You do not have to include them in your app code.You can start making changes in your app assuming the plugin dependency and plugin itself is already included in the app.
It is worth mentioning that you can not test an app using third party cordova plugin in emulator.This is one limitation which will increase your development time.But we can expect that things will improve in near future.
Intel XDK really makes it very easy to add plugins.The only improvement I would like to see is emulator support.If we can test the plugin with in emulator then it will be great.Currently you can build the app and then test it on your device.It does increase your development and testing time.
I did find it time consuming.But most the plugins come with documentation and you only need pretested few lines of code to include the functionality.In future releases may be Intel will take care of this thing.But as of this writing it is not.
Free free to share your queries and thoughts.