Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Getting started with Cordova

#Setting up a Cordova Project #####HMTL London, 2014-07-23

Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript

PhoneGap is Adobe's implementation of Cordova. PhoneGap also offers the PhoneGap Build service. This is not covered here.


Install from NPM. Install node.js if you don't have that)

sudo npm install -g cordova

// I had to do this first time:
sudo chown -R ade /usr/local/lib/node_modules/cordova/

// to update
sudo npm update -g cordova

// get version
cordova -v

Create a project and add iOS and Android

cordova create AmazingApp com.adeweb.amazing "Amazing App"
cd AmazingApp/
cordova platform add ios
cordova platform add android

// list platforms added to this project
cordova platforms ls

Add plugins

// e.g.
cordova plugin add org.apache.cordova.device
cordova plugin add

Prepare / build / run

cordova serve        // run locally w/cordova API available
cordova build ios    // alias for prepare + compile
cordova run android    // run on attached device

You can also open the project in XCode or ADT and work from there.

Get device info from Device plugin

alert("Platform is " + window.device.platform + " version " + window.device.version);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.