Thursday, October 8, 2009

Google Android without Eclipse

Android & Eclipse

My only real complaint with the android project so far is how heavily the Eclipse IDE is pushed. I personally do not find IDEs helpful, they hide the project under a level of abstraction I find distracting, not convenient, and I've found working with developers who are dependent on IDEs to be frustrating. I am an Emacs jockey, but have structured this post to focus on the android tools, and how to work with an android project independent of Eclipse. As of its writing this tutorial focuses on using the latest release of the android SDK which is 1.6.

Install

Download the new android SDK, I place mine in '/usr/local', and create a symlink to to the SDK in that directory named 'android' like this.

ln -s android-sdk-mac_x86- android
That way I can update my sdk without having to edit my profile, just change the symlink to the new sdk. Next make the necessary edits to your profile, and make sure you load the profile for the edits to take effect. Here is an example of how I have my .bash_profile set up like this.

HOME=/Users/jgoodell
export HOME

ANDROID_HOME=/usr/local/android
export ANDROID_HOME

ANDROID_SWT=$ANDROID_HOME/tools/lib/x86
export ANDROID_SWT
PATH=$ANDROID_HOME/tools:$PATH
export PATH

I set two variables for convenience that are not necessary 'HOME' and 'ANDROID_HOME', I find that these variables come in hand all over the place, and instead of having to type these common long paths over and over, increasing the likely hood of a typo, I can use the variable in constructing paths. The two important variables are 'ANDROID_SWT' and 'PATH' which are needed for finding the android tools, and the swt jar file android needs to function.

Creating a Project

Once you have created an 'avd' the next step is to create a project, to do this without relying on Eclipse you invoke android with the following action and options.

android create project --package com.example.helloandroid --name HelloAndroid --activity HelloAndroid --target 2 --path
This follows the outline in the android 'HelloAndroid' tutorial.

Running Emulator

To start the android emulator without using Eclipse you will use the emulator tool and supply the 'avd' you created earlier. I start this as a backgroud operation so I can do everything from the same shell.

emulator -avd &
This will start the emulator, and from here you can load your application.

Loading Your Application

I find using the built in ant script to be the most useful and for that you simply have to type

ant install

while the emulator is running, this is why I start the emulator as a background process, and you are ready to test your application in the emulator.

Wrap Up

There, those are the basics of getting an android project running without having to rely on Eclipse.