Android SDK on Mac OS

So you're on a Mac, and you need to test your cool website on Android, except you don't have any Android-powered device? Read on.

(The following have been tested on Mac OSX Snow Leopard and Lion)

  1. Download the Android SDK on this page: http://developer.android.com/sdk/index.html
  2. If you don't have it, create a bin directory in your home folder (~/bin)
  3. Extract your Android SDK zip archive into it, so you should have ~/bin/android-sdk-macosx
  4. Add ~/bin/android-sdk-macosx/tools directory to your $PATH environment variable:
    • for this, open ~/.bash_profile (create this file if it doesn't exist) in your text editor, then add the following line (modify yourusername): export PATH="$PATH:/Users/yourusername/bin/android-sdk-macosx/tools directory"
  5. To update your current shell's environment variables, execute this in the terminal: source ~/.bash_profile
  6. You should now be able execute the android command. If it shows "No Java runtime present, requesting install", and a message dialog asking you to install Java, proceed with this installation as Android SDK needs Java to work.
  7. Once you've executed android, a window should appear, listing some Android SDK files. We will need to install some "Platforms". For my part, I installed the packages that are selected by default (Android 4.0.3 (API 15), at the time of writing this). But feel free to download as many Platforms as you wish.
  8. When you're done loading packages, you can click on Tools > Manage AVDs… from the Android SDK Manager app. Doing so will show you a Window named "Android Virtual Device Manager".
  9. Click on "New…" to add a new Virtual Device.
  10. Name your device something like "my_avd" (dont put any space or special characters in it)
  11. Choose your target. In my case, I chose "Android 4.0.3 - API Level 15".
  12. I suggest you keep every other settings at their default values and click "Create AVD". Doing so should display a dialog that says that your AVD was created. Click OK.
  13. Now, you should be able to run this AVD with the emulator command provided by the SDK, which is inside the "tools" directory, like the android command. So in your terminal, run the following command emulator @my_avd , where my_avd is of course the name of your AVD.
  14. You should see the DDMS app opening, and a dialog thanking you for using Android SDK. Note: I like to help the people that give me free tools to test my apps, so I recommend you check "Send usage statistics to Google", and click "Proceed".
  15. Wait for your virtual device to boot. Depending on your hardware it may take a couple of minutes. After which everything should work fine.
  16. Oh yeah, and since this tutorial is about testing Web applications, you can open the Web browser by clicking on the lower right (earth) icon.

If you're testing a Web app that you're developing locally, you will need the IP address of your machine, in place of 'localhost'. Doing an ifconfig in the terminal will give you this address.

And that's it!