Saturday, 16 January 2010

Android Development Environment on Ubuntu

I bought a Nexus One Google phone. Some day I thought I'd play around with the development possibilities, and in an idle moment last night, I wondered how hard it would be to get a "hello world" going.

I started with my laptop running Ubuntu 9.10, my Google phone and the USB cable to connect the two together.

Step one is to download the SDK. The link is indicated above. I just downloaded the Linux version and decompressed it into a folder under my user directory I set aside for Android stuff. I edited my ~/.bash.rc to add the tools directory to the path as they recommended also (see link below).

Next step was to install the ADT, which is an IDE based on Eclipse with all kinds of niceties for developing and compiling Android apps. Think of it like Visual Studio for Android. First step is to install the base version of Eclipse, so I can then add ADT as a plugin. So to begin, from the terminal:

sudo apt-get install eclipse

After that installs (over 200mb) I started up Eclipse (installs a link under "Programming" in the Gnome menu bar, which I moved to the desktop where I like my icons). As an aside I understand version 3.5.1 of Eclipse is required by the ADT, however by co-incidence this is the version which is installed by default in Ubuntu 9.10 when you apt-get eclipse. So those using another distro or version may need additional steps to ensure the correct version of Eclipse.

I then followed the steps below to install the ADT into Eclipse, basically going to help > install software and adding the URL Google provide for the ADT, and next, next finishing.

However there was one "gotcha", in that some third party libraries could not be found. I found the answer in a mailing list post (second link below) - basically I needed to add the Eclipse update site to the install of Eclipse - so the ADT can pull in some third party libraries. This allowed me to complete the ADT installation, which by the way took about 20 mins.

The final step in setting the ADT up is to associate the SDK with the ADT install. This is done by going into window > preferences in Eclipse, and on the Android page pointing at the location where the SDK is installed.

So, having downloaded the SDK, decompressed it, installed eclipse, installed the ADT into Eclipse and pointing it at the SDK I was ready to go? Not quite - Google have different version of the Android OS, and provide different modules for each. The Nexus One is Android 2.1, or API level 7. Frankly I don't really care about older versions, so I was just interested in the 2.1 SDK. I therefore followed these steps to install the 2.1 SDK:

All that being complete I followed the documentation to write a "hello world application".

As indicated in the tutorial, as a first step I ran the app on the emulator which I created as part of the tutorial. But really I was interested in seeing the application on my phone. The steps for that were here:

Again the Google documentation was excellent - however one Gotcha on Ubuntu was the adb server needs to be run as root, otherwise you see an access denies message. This can be done by starting the server as follows:

sudo /path/to/sdk/tools/adb start-server

And that was it! I had the "Hello world" on my phone. We were watching Raiders of the Lost ark in the background while I was tinkling on my laptop, and as a guide I started this when Ballac takes the statue off Jones in the Andes, and was completely finished by the time Jones miraculously arrives at the submarine base towards the end.

No comments:

Post a Comment