Updating Cordova (PhoneGap) to version 3.x

2014-04-26

When I started out writing Best Books PhoneGap had recently open-sourced to Cordova and I began using version 2.0. Since then much has changed and Cordova is up to version 3.4.0 at the time of writing. Unfortunately updating is no longer a case of swapping a few files and editing a config file. I’ve been following the Cordova docs but also expanding on this as there was a little detail missing.

Firstly it’s worth switching to the CLI (Command line interface) and following the guide up until you need to add the platforms. This is about were I had to deviate from the guide a bit. Firstly you’ll need node JS installed if you don’t already as this gives you the package manager (npm). All good here but I had an error when trying to add the android platform. I had the SDK but no Ant! This is where you need to go off and grab it from apache and then follow a few steps to set it up.

Apache has a manual you can follow but to summarise it’s basically as follows (for Windows). Download Ant and unzip the binary into a suitable location. Open up your system environmental variables and add the path to the Ant bin folder to your PATH, add the root Ant folder as a new variable ANT_HOME and make sure your JAVA_HOME is set too (C:Program FilesJavajdk1.7.0_45 in my case). Confirm this with “ant -version” from the command line.

Ok, in my case this got me to the next error (“an error occurred while listing android targets”) and this ended up being the adt sdk tools missing from the path. Add the path to your sdk as ANDROID_HOME if you want for easier referral in you path but basically you need the tools and platform-tools paths in your system PATH variable.

Next up was a complaint about needing to install Android target 19 (the newest Android SDK). So fire up the SDK Manager executable and select the required packages and wait for the download to finish. After that when you attempt the platform add android command it should run smoothly. The platform ls command will tell you if it installed correctly.

That’s pretty much it. Now you can continue with the Cordova guide to build and run you application. It’s a bit of a hassle to move from an older version of Cordova/PhoneGap but the new CLI adds a lot of power and flexibility, especially for multi-platform development.

Oh and if you like using Eclipse plus the Android Developer Tools rather than just launching the emulator or device from the command line, you may encounter a problem after you’ve updated your SDK. It will tell you that you need to update ADT to match the SDK but sometimes Eclipse won’t actually find the updated tools as it’s not in your feeds. Follow this guide to fix that. Also you’ll need to add the project as a “new project” -> “other” -> “Android existing project” and select both checkboxes (include the cordova library).


Comments: