Friday 2 October 2009

Setting up the environment for Android development on a Mac - from zero to helloWorld

Zuhlke engineering - the company I work for - held a training camp in Spain, and one of my tasks is to design and develop an Android application. The idea I have come up with is called "Find my Android" - to retrieve the geographical information of the device after lost or thief. I worked with my colleague Immo for two days but failed to achieve anything valuable - partly due to the lack of Internet connection, and partly due to under-estimating its compact.
Anyway, I am determined to finish my Android application properly, and as I want to boarden my technical horizon by exploring the Mac OS, the first challenge would be to set up the Android development environment on it.
As a newbie to both worlds, I was curious and worried from the beginning, but the whole process turned out to be smoother than I would have imagined - it took me around one hour to get it done - with Dido by my side. However, those more seasoned Mac users can skip the following, as you are too familiar with the operations, and the development guide provided by Google should be straight-forward enough to you.

So here we go - to Android and beyond.

1. Installing the SDK.
I first downloaded the SDK, and the trouble I got myself into after this is to install it. The development guide refers to the .bash_profile file, which turns out to be invisible or even non-exist in the first place. So, to create it, you just need to bring up your terminal, and key in the following command:
touch ~/.bash_profile
and "~/" is really the command line shortcut for Macintosh HD->Users->your_user_name (a.k.a. your "Home" folder)
As the requested file just came into being, you want to edit it to include the path of your Android SDK. And you key in the following command to bring up the TextEdit and open the .bash_profile file for edit:
/Applications/TextEdit.app/Contents/MacOS/TextEdit ~/.bash_profile
and you stick in /tools, save it, and quit.

Then you continue to follow the Google guide and install the ADT plugin for Eclipse, if Eclipse is your choice (why not?). There should not be any problem, as it is very similar to what we did on Windows.

2. Creating an AVD
If you are a eager person as I am, you might have already skipped the introductions and headed for the HelloWorld example.
Another tricky thing here is to create an AVD, I was expecting the command in the tutorial to just work, but it keeps complaining about not being able to find the android command. I then open the tools directory under the Android SDK path, just to find a android executable there.
Googled it, and I got the following tip: use "./android" instead of just "android", which makes:
./android create avd --target 2 --name my_avd
and it magically works. -_-|||

So far so good, actually, if you are getting here, you are pretty much there - just follow the HelloWorld example and wait for the emulator to pop up. As I observed, the emulator loads much faster than it does on Windows, or is it because I really need to have a new laptop for work soon?