Saturday, May 3, 2014

Cordova - Build your application simultaneously on multiple mobile platforms!

Let's quickly put together a basic Cordova project.

INSTALLATION
We will be using Node Packaged Modules, so
$brew install node
$npm install -g cordova
$npm install -g cordova-cli
-g is needed for global access

SAMPLE PROJECT STRUCTURE
$cordova create projName com.package.name "Initial display of text"

Enter into the directory
$cd projName

Add platforms of development
$cordova platforms add android
$cordova platforms add ios

Edit the index.html page with the contents to be displayed.

Build Project
ios SDK is needed for it. Xcode 4.6+ supports this.
$cordova build ios
OR
$cordova build android
To start the simulator
$cordova emulate ios
OR
$cordova emulate android

This gets the basic setup of Cordova based IOS/Android app running.

NOTE: PLUGINS

A functionality that needs to be implemented natively is done by using plugins:
Eg: To add native alerts
$cordova plugin add org.apache.cordova.dialogs
<script src="cordova.js"></script> is needed in index.html so that CLI injects it at build time. cordova.js needn't be there in www folder.