Sep 02

cordova and installing the Android Development Toolkit (ADT)

Category: Linux   — Published by goeszen on September 2, 2014 at 10:53 pm

Probably it's just me but adding platforms on cordova CLI wasn't so intuitive for me at first. Following the guide on the cordova docs didn't tell me everything that was needed to get it up and running for Android. The thing is, npm installs cordova, but not the Android SDK (or the iOS SDK, or a Java JDK) and this is needed by cordova to build your app.

First, on Ubuntu 14.04, I had to install the lib-nodejs-legacy package which links /usb/bin/node with /usr/bin/node.js

So go to google's and download the SDK here. It's a .tgz file. Extract it somewhere and then move it where you want this toolchain to live on your system. I moved it to /opt/andorid-sdk-linux. After that, you need to adjust your export variables in ~/.bashrc (via). Add this with nano, or the editor of your choice:

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

export ANDROID_HOME=/opt/android-sdk-linux/tools
export ANDROID_PLATFORM_TOOLS=/opt/android-sdk-linux/platform-tools

Start a new shell terminal to have the bashrc re-read.

Then execute android: $android
The android binary/script is like npm with a GUI, or cpan, or apt-get, synaptic, or similar package managers, only for android. A nice GUI will come up and it will tell you which packages are already there (from the tar, linked up by you via bashrc) and what's missing. By default, the most recent release (in my case API version 20) was already checked. Confirm to download and install the selected packages.

Where is the android SDK supposed to live? (Answer: where you want)
I get an error: "ubuntu cordova An error occurred while listing Android targets" (Answer: read above, are you sure you have the SDK at all?)
Ubuntu install Android SDK (this post is the answer)

Install the Java JDK

Try executing $ ant -version
In case it complains, your JDK (not JRE) is not there or your paths are not pointing there. On Ubuntu, do this:

sudo apt-get install openjdk-7-jre icedtea-7-plugin
sudo apt-get install openjdk-7-jdk openjdk-7-source openjdk-7-demo openjdk-7-doc openjdk-7-jre-headless openjdk-7-jre-lib

Normally, paths would point to /usr/lib/jvm/java-7-openjdk-amd64/jre, but make sure you point to /usr/lib/jvm/java-7-openjdk-amd64 in bashrc - the parent directory populated by installing the openJDK development libraries

Leave a Reply