Android SDK on Ubuntu

January 27, 2010 at 12:08 AM | categories: Android | View Comments |

Since I got the N1 a few days ago, I'm quite interested in hacking for the Google Android platform. One of my favourite things about Android is that the SDK is freely available for Windows, Mac and Linux. In fact there is even an an effort to port to *BSD systems, although that still seems FreeBSD-specific and in the early stages.

Anyway, I decided to do my Android development under Ubuntu. While its pretty straight forward to get things set up, there are a few gotchas and little pieces missing from the Google docs to install the Android SDK on Ubuntu.

Download and unpack the SDK


First step is to download the SDK from the Android SDK page. I got the Linux/i386 version. Untar it to some convenient location. I just dropped it into my homedir. Then add /tools to your shell $PATH:

# assuming your shell is bash
$ echo 'export PATH=$PATH:~/android-sdk-linux_86/tools' \
     >> ~/.bashrc

Now you should have the SDK tools in your path to make using Android SDK easy! To verify, try running adb help and you should see a bunch of output.

Configure USB for your device


This is optional I suppose since you can use the emulator. However I really wanted to be able to debug on a physical device (my Nexus One). This is one area where the Google docs are lacking, at least for Ubuntu Karmic (9.10). You will want to refer to the Developing on a Device page, if only for the USB Vendor IDs table.

You need to create a file called /etc/udev/rules.d/51-android.rules on your system. Its contents should be (you might have to change vendor ID):

SUBSYSTEM=="usb", SYSFS{idVendor}=="0bb4", SYMLINK+="android_adb", MODE="0666"

Note that "0bb4" is the HTC Vendor ID. If you don't have a HTC phone (e.g. G1, N1) - then you'll need to look up your vendor ID at the page I linked above, or this copy of the table here:

Manufacturer USB Vendor ID
Acer0502
HTC0bb4
Huawei12d1
LG1004
Motorola22b8
Samsung04e8
Sony Ericsson0fce

You might need to reboot or restart udev (`sudo service udev restart') in order for this to take effect.

Enable USB debugging on your device


The next step is to enable USB debugging on your device so that it becomes available to the Android SDK USB system. Hit Settings -> Application Settings -> Development -> Enable USB Debugging to turn it on.

At this point you can plug in your device, and adb should pick it up:

$ adb devices
List of devices attached 
HT9CRP806806    device

Install Eclipse and ADT Plugin


You don't have to use the SDK with Eclipse, but I figured I'd give it a shot to check out the tools and to hold my hand a bit in terms of project creation. Again this is mostly documented by Google, but you can take a few shortcuts on Ubuntu Karmic:

$ sudo apt-get install eclipse

Now to get the ADT plugin, you have to follow the instructions from Google. I had to disable https for some reason to get it to install, and use a plain http URL instead.

Create an AVD


At first, it wasn't entirely clear to me that I had to actually go and create an

Get Platform SDKs
Click "Available Packages". Then click "Add Site" and enter https://dl-ssl.google.com/android/repository/repository.xml. This will populate your available packages list with a whole load of SDK platform versions and so on. Install whichever ones you want to be able to use. I just went with 2.1 for starters since thats the version I run on my phone. Presumably when you get around to compatibility testing for your app you will want to also install earlier versions. Correctly configured, it should look like this:

Create virtual device (target)
Now that you have a platform sdk available, you can create the AVD. Click "Virtual Devices" and then the "New" button. You should be presented with this dialog:

Its pretty clear what to fill out here. One thing to note is that if you want to be able to access the 'Net from within the emulator (as you almost certainly do) you need to add "GSM Modem support" to the AVD. Click "New" under the Hardware area to do this.

Running the Android SDK Emulator


Once again, start the AVD manager (by typing 'android'). Now you can select your AVD and click "start". It can take a little while for the emulator to boot:

There you have it! To get started with building a project and getting it running on the emulator, try playing with Eclipse. It makes it pretty easy to get started. I hope to write more about Android development as I learn!

Niall O'Higgins is an author and software developer. He wrote the O'Reilly book MongoDB and Python. He also develops Strider Open Source Continuous Deployment and offers full-stack consulting services at FrozenRidge.co.

blog comments powered by Disqus