I’m just starting to look at writing Android apps for the first time and lets just say my Helloworld experience was not ideal. Things just didn’t exactly work first go and when it did work it would suddenly stop working, then start working again and so on (see Troubleshooting for details). Not all that inspiring when all you are trying to run is Helloworld!

Preconditions

Allow me to set the scene:

Platform: Mac OS X 10.6.5 (Snow Leopard)
IDE: Eclipse
Android SDK: 2.3

I’m using Eclipse because it would seem that it has better Android support than NetBeans currently (and comes recommended by http://developer.android.com) so let’s roll with that. Being a Java developer I already had Eclipse Java EE for Web Developers – Galileo (64-bit) on my machine so I am using that. Check http://developer.android.com/sdk/requirements.html to see if your version of Eclipse is compatible before proceeding.

Setup

I will try and gloss over the setup instructions for Android dev since you can find them in great detail online already. In brief:

  1. Download the Android SDK http://developer.android.com/sdk/index.html and extract (avoid white space in your path to SDK). Add/modify your PATH variable within .bash-profile (where <pathToAndroidSDK> is something like “yourInstallPath/android-sdk-mac_86″):
  2. export PATH=${PATH}:<pathToAndroidSDK>/platform-tools:<pathToAndroidSDK>/tools
  1. Install the ADP plug-in for Eclipse. In Eclipse go to¬†Help –> Install New Software… –> Work with: https://dl-ssl.google.com/android/eclipse/ –> Press Enter. Check “Developer Tools” when it appears in the list and complete the install.
  2. Open Android SDK and AVD Manager (Note. This can also be done inside Eclipse Window –> Android SDK and AVD Manager) :
  3. $ cd <pathToAndroidSDK>/tools
    $ ./android
  4. In Android SDK and AVD Manager create a new virtual device. Mine had the following custom properties:
  5. Name: Android2.3
    Target: Android 2.3 - API Level 9
  6. Once your AVD has been successfully created, start Eclipse.
  7. In Eclipse, create a new Android project File –> New Project –> Android Project. Mine had the following custom properties:
  8. Project Name: AndroidHello
    Build Target: Android 2.3
    Application Name: Hello
    Package Name: com.codenes
    Create Activity: AndroidHello
    Min SDK Version: 9
  9. Expand the newly created project in the package explorer. Under the src directory you will find AndroidHello.java. We are going to modify this file ever so slightly to present the text “Hello, Android” on application startup. Modify this file to look like the following:
  10. Save your project. Let’s try and run it. Right click on your project in the package explorer and select¬†Run As –> Android Application.
  11. You should see the emulator appear and your Eclipse console should print out some promising messages as it launches the emulator, uploads, installs and finally starts your app. I have to say that this whole process is pretty darn slow for my liking.
  12. The only notable thing at this point is the application doesn’t always start up automatically which was what I expected. It seems like it only does the first time it is loaded onto a new emulator as far as I can tell. I found that I had to hit the menu button subsequent times to launch it.
  13. Check out your app (in all it’s awesomeness) then navigate to the apps screen in the emulator to discover that it can also be launched through the icon “AndroidHello”.

Removing Your Application

  1. Start the Emulator if it is not already running.
  2. Open a terminal:
$ cd <pathToAndroidSDK>/platform-tools
$ ./adb shell
# cd data/app
# ls (to view all of the .apk apps installed on the emulator)
# rm <yourApp.apk>
# exit

Troubleshooting

  • Be careful specifying a SD card size when creating your Android Virtual Device. Initially I put some default value in this field and I was getting the following error in the Eclipse console (app killed almost immediately after startup):
  • Use LogCat to examine more meaningful error messages if you are having problems running your app. In Eclipse go to Window –> Show View –> Other –> Android –> LogCat. E.g. for the above problem with the SD card value I was seeing “Low Memory” messages in LogCat prior to processes being killed which led me to the problem.