Open main menu

CDOT Wiki β

MAP524/DPS924 Lecture 11

Revision as of 22:51, 10 August 2015 by Andrew (talk | contribs) (Setup)

Cordova

Cordova (used to be and sometimes still is called Phonegap) is a way to write your app using HTML/CSS/JavaScript instead of Java/XML. Theoretically this also makes your application platform-independent, you can build it for any version of Android, iOS, Blackberry, etc.

It relies on the idea that most everything you want to do in an application is available in the modern HTML5 standards, but clearly some things are not - for example access to the camera. For things like that Cordova offers plugins: chunks of native code that give you a JavaScript interface to the device features not normally available from a browser.

Setup

The Cordova development tools are easiest to install using npm, that's a package manager that comes with Node.js. You'll first have to install node.js:

su - # or sudo su -
apt-get install npm nodejs nodejs-legacy # nodejs-legacy is just a symlink from "nodejs" to "node"

You also need git but you should already have that installed (presumably you used it for the assignment). Now you can install Cordova (also as root):

npm install -g cordova

Create a project

You could create an Android project as you normally do and turn it into a cordova project, but you may as well use the cordova command to do it for you. First step is to generate the project structure:

cordova create cordova-test ca.littlesvr.cordovatest HelloWorld

It will create the directory cordova-test with your application code under "www". You can start working on your app at this point but there's one more thing you need to do before you can build an Android version:

cordova platform add android

Now under platforms you have an android directory which has all the android-related project files, but don't bother trying to open that with Android Studio or building it directly with gradle - you'll just get a headache. Instead use the cordova command again:

cordova build

Once that is done it will tell you where is the generated .apk file and you can install it using adb.