How to: test web applications with the Android SDK on Mac OSX Lion
// March 30, 2012
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)
- Download the Android SDK on this page: http://developer.android.com/sdk/index.html
- If you don't have it, create a bin directory in your home folder (~/bin)
- Extract your Android SDK zip archive into it, so you should have ~/bin/android-sdk-macosx
- Add ~/bin/android-sdk-macosx/tools directory to your $PATH environment
- 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"
- for this, open ~/.bash_profile (create this file if it doesn't exist) in your text editor, then add the following line (modify yourusername):
- To update your current shell's environment variables, execute this in the
- You should now be able execute the
androidcommand. 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.
- 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.
- 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".
- Click on "New..." to add a new Virtual Device.
- Name your device something like "my_avd" (dont put any space or special characters in it)
- Choose your target. In my case, I chose "Android 4.0.3 - API Level 15".
- 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.
- Now, you should be able to run this AVD with the
emulatorcommand provided by the SDK, which is inside the "tools" directory, like the
androidcommand. So in your terminal, run the following command
emulator @my_avd, where my_avd is of course the name of your AVD.
- 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".
- Wait for your virtual device to boot. Depending on your hardware it may take a couple of minutes. After which everything should work fine.
- 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
And that's it!
Questions? Comments? Feel free to contact me.