How to set up the Android Emulator on a Mac

You wouldn’t think that a post like this would be necessary, but as I recently went through a frustrating bit of config hell in what I’d expected to be a straightforward process, I thought I’d write down the procedure that worked for me.

Download and install Android Studio

  1. Download the latest version
  2. Follow the instructions on the next page

Install the latest SDK tools

Detailed instructions can be found here, but to summarize:

  1. Open the GUI
    cd ~/Library/Android/sdk/tools
    ./android sdk
  2. Select the following from the Tools folder:
    • Android SDK Tools
    • Android SDK Platform-tools
    • Android SDK Build-tools
  3. Select the System Image and SDK Platform for the Android version you want to emulate.
  4. Click Install packages…

Set up an AVD file

At this point, you should be able to just run the Android emulator, right? No, this is the point at which your hopes and dreams are put on hold while you Google around, trying to figure out how to configure and run the emulator, then debug the same couple undocumented problems that everyone runs into. #rage

In order to run the Android simulator, you will need an “Android Virtual Device”. You could create one from the command line, but let’s use the GUI for now.

  1. Open the GUI
    cd ~/Library/Android/sdk/tools
    ./android sdk
  2. Select Tools → Manage AVDs…
    In order to get the menu to show up, I had to click to an unrelated window, then back to the Android SDK Manager window. Weird.
  3. Click Create…
    Be sure to enter the following fields:

    • SD Card → Size: 2048 MiB
    • Use Host GPU
    • Keyboard → Hardware keyboard present

This last bullet points are important. If you don’t set up an SD Card, then the browser will immediately crash for no apparent reason. Likewise, you need to check the box next to “Use Host GPU”, or the browser will crash with the same unhelpful message. And checking “Hardware keyboard present” will allow you to use your Mac keyboard (instead of having to poke at the UI with your mouse).

Here’s an image of the sample AVD that I created:

avd

Run the emulator

At this point, you should be able to run the emulator with the following command:

cd ~/Library/Android/sdk/tools
./emulator -avd my_avd

Debugging

If you run into any problems, it’s useful to know how to access the console logs. Once the emulator is running, do the following:

cd ~/Library/Android/sdk/platform-tools
./adb shell

This will get you into the Android device. To see the logs, run:

logcat

Good luck!

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

2 thoughts on “How to set up the Android Emulator on a Mac

Leave a comment