How to take a screenshot of your Android device using DDMS on a Mac

I just installed the Android SDK on a new Mac in order to be able to save and share screenshots of the Android apps I'm testing, and I thought it would be a great idea to document the process.

Step 1: Download the SDK

Go to http://developer.android.com/sdk/index.html and click on "Download the SDK for Mac".

download the Android SDK for Mac

Step 2: Add the "tools" directory to your PATH

The Android Developers site offers the following tip at the bottom of the Adding Platforms and Packages page:

For easy access to the SDK tools from a command line, add the location of the SDK's tools/ and platform-tools to your PATH environment variable.

When I write tutorials, I try to avoid assuming my audience is as experienced as I am. Therefore, I'm going to show you how to set your PATH environment variable, which tells your computer, "When I run a program from the command line in Terminal, please look for that program in these directories."

The best way to set the PATH variable is to add it to your .bash_profile, which is a file that is read every time you open a new Terminal window or tab. You can use it to customize many aspects of your Terminal session.

If you already have a .bash_profile, and if it already contains your PATH in a line that looks like export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH", then simply open it with your favorite text editor, and add the location of the tools directory to your PATH:

export PATH="/usr/local/bin:/usr/local/sbin:~/bin:~/Downloads/android-sdk-macosx/tools:$PATH"

Here's how we came up with that: if you downloaded the Android SDK to your Downloads folder on your Mac, and if the name of the SDK folder was android-sdk-macosx, then the location of the tools folder will be ~/Downloads/android-sdk-macosx/tools. The tilde (~) is short for your user directory. For example, my OS X username is moncef (you can find out what your username is by running whoami in Terminal), so my user directory is Users/moncef. Instead of typing Users/moncef/Downloads/android-sdk-macosx/tools, we can use the shortcut: ~/Downloads/android-sdk-macosx/tools.

If you don't already have a .bash_profile, then you can create it and add the PATH to it all in one step via the command line:

$ echo 'export PATH="~/Downloads/android-sdk-macosx/tools:$PATH"' >> ~/.bash_profile

The echo command takes everything between the single quotes and adds it (>>) to a file called .bash_profile in your user’s root directory (~/).

Now that the PATH variable is set, save .bash_profile, then quit and relaunch Terminal.

Step 3: Install the Android SDK Platform-tools

Run the following command in Terminal:

$ android sdk

This will launch the Android SDK Manager, which is a Java program. If you're prompted to install a Java update, go ahead and install it, then run android sdk again. Once the Android SDK Manager is up and running, uncheck everything except for Android SDK Platform-tools under Tools. For the purpose of taking screenshots, that's all we need, but if you're going to be developing or using the Emulator, you will need to install at least one of the other packages.

android sdk manager

Click on Install 1 package at the bottom left, then click on Install once the Choose Packages to Install window appears. This will create a new folder inside android-sdk-macosx called platform-tools.

Choose Packages to Install

When you see Done loading packages, click Close, then quit the Android SDK Manager.

Android SDK Manager Log

Step 4: Add the "platform-tools" directory to your PATH

Just as in Step 2, we now need to add the newly-created platform-tools directory to our PATH variable:

export PATH="~/Downloads/android-sdk-macosx/tools:~/Downloads/android-sdk-macosx/platform-tools:$PATH"

Save .bash_profile, then quit and relaunch Terminal.

Step 5: Enable USB debugging on your Android device

Go to Settings -> Applications -> Development and turn on "USB Debugging".

On the Jellybean OS, go to Settings -> Developer options (under System). Turn ON the Developer options via the button in the top right, then check USB Debugging.

Additional steps for Kindle Fire

Run the following command in Terminal:

$ android update adb

This creates a file called adb_usb.ini in ~/.android/ that contains the following text:

# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.

Open that file in your favorite text editor, and on line 4, type 0x1949 then press return. You should end up with 5 lines, like this:

# ANDROID 3RD PARTY USB VENDOR ID LIST -- DO NOT EDIT.
# USE 'android update adb' TO GENERATE.
# 1 USB VENDOR ID PER LINE.
0x1949

Save the file, then kill and restart the adb server:

$ adb kill-server
$ adb start-server

Step 6: Connect your Android device to your computer

Verify that your device is detected:

$ adb devices

Step 7: Run DDMS

From the command line:

$ ddms

This will launch the Dalvik Debug Monitor, and you should see your device listed in the top left pane. Click on your device name, then select Device -> Screen capture... from the Menu, or use the keyboard shortcut ⌘S.

Screen capture in DDMS Dalvik Debug Monitor