Thursday, April 23, 2009

Adventures with Android - 1

Since I'm so convinced that Android is going to take over the world ;-), I decided to walk the talk and try some Android development.

My desktop machine runs Ubuntu 8.10 (Intrepid Ibex) and I have OpenJDK 1.6.0_0-b12 installed. Ubuntu 8.10 doesn't give you the latest version of Eclipse (3.4 - Ganymede), so I downloaded and installed it separately.

Then I pointed Eclipse to the Android SDK plugin site and installed both the Android Development Tools and Android Editors. I have no idea what Android Editors are required for, but bandwidth is cheap, so what the hell...

I have no idea why, but I also downloaded the Linux version of the Android SDK separately. (Maybe I downloaded this before the Eclipse plugin, I don't remember.) My standard policy is to install all software under /usr/local with the exploded directory having the full version number, then to create a symbolic link without a version number, which points to the latest directory.

i.e., /usr/local/android -> /usr/local/android-1.1r1

[This way, I can keep multiple versions of software installed simultaneously, while pointing to the latest version through the symbolic link. If required, I'll use the symbolic link in PATH and CLASSPATH variables, so I don't have to change them when I upgrade or downgrade versions. The power of symbolic links...
Unix was pretty cool even twenty years ago :-).]

If I now open a terminal window and go to /usr/local/android/tools, I can execute the Android emulator by typing "./emulator". Be warned that even though the emulator comes up right away, it takes a few minutes for it to fully initialise and display its beautiful mobile screen.


I played around with the emulator for a while. This is pretty cool. The apps actually work. I checked out the browser. I could see my own blog. Then I went to Google Maps and saw my own house. It's pretty eerie, sitting inside my house at a computer running an emulator running a browser that shows a street view of the same house from the outside. MC Escher would have loved that.

Well then, the next step was to follow the tutorial and build my first Hello, World application on Android. The tutorial is designed for Eclipse with the Android plugin. I followed it fairly faithfully and got my first application running.


It was only when I tried to deviate from the script that I ran into trouble. The tutorial advised me to edit the "strings.xml" file in "res/values", but I couldn't see the file in the Java perspective. So I thought I'd create one, but I couldn't because Eclipse told me a file with that name already existed! No problem, I thought naively, let me at least try and create a "strings2.xml". After that, the application simply stopped working. I'm sure it was because of the empty XML file that I had created, but the SDK didn't allow me to even see the file so I could remove it. I don't remember what sequence of steps I followed to finally see the two XML files and remove the offending "strings2.xml". The app started working again, to my relief.

If anyone at Google is reading this, please note that even non-newbie Java developers can find the Android SDK confusing in places.

Anyway, that was my first baby step into the world of Android. I'll continue to blog about this as and when I get time to progress through the tutorials and build more stuff.

2 comments:

Unknown said...

Hi Ganesh! Good post, but can you helkp me with a problem? I am NOT a developer, yet I have a developer phone (early adopter in the UK, wanted G1)
Now, I don't know how to manually update my phone to cupcake. Can you help me with step by step directions? I have tried from HTC site, even downloaded the sdk kit but i don't even know how to install it! Help? Please?
Thanks in advance. Brian

prasadgc said...

Hi Brian,

I haven't done this myself, but I found a link that may be useful:
http://androidandme.com/2009/05/guides/beginners-guide-for-rooting-your-android-g1-to-install-cupcake/

Hope this helps.

Regards,
Ganesh