Skip to content

Instantly share code, notes, and snippets.

@aderowbotham
Last active August 29, 2015 14:04
Show Gist options
  • Save aderowbotham/bb95d8f7f4caf1612a99 to your computer and use it in GitHub Desktop.
Save aderowbotham/bb95d8f7f4caf1612a99 to your computer and use it in GitHub Desktop.
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

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 org.apache.cordova.network-information

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