The official Android Developers page has a detailed documentation about Android Debug Bridge (adb). This post summarizes the adb commands that I (an android game developer) use daily.
adb devices
If you have more than one device/emulator attached to your computer you must specify on which device/emulator the adb command will run. adb devices command lists all the attached devices.
You can direct a command to a specific device with the -s option:
Mute all the logs except “SpadesPlus” and “HeartsPlus” tags:
By default logcat output format is:
priority/tag(process id) : log message
-v option lets you specify output format. For example :
adb logcat -v raw : Displays developer log message without any other meta-data
adb logcat -v threadtime -s "SpadesPlus" : Displays logs with tag “SpadesPlus” with information about the thread writing the log message.
ndk-stack
ndk-stack is a tool that is distributed with the Android NDK. It allows you to filter stack traces as they appear in the output of ‘adb logcat’ and replace any address inside a shared library (*.so files) with the corresponding values.
Usage : adb logcat|ndk-stack -sym obj/local/armeabi/
Here is an example:
ndk-stack will translate something like
into more readable output (see the line numbers in the stack stace?):
adb push/pull
Command below copies (uploads) “my_movie.mp4” file to the Movies directory on the sdcard of the attached device. No need to open a file manager!
Similarly you can copy (download) a file from the attached android device to your computer:
adb shell
Android devices come with a shell program that you can use to execute commands. To enter a remote shell on a device/emulator just type adb shell. To exit the remote shell type “exit” or “CTRL+D”. You can also issue single commands without entering a remote shell:
enable/disable wifi (command line)
With the adb shell command you can enable/disable wifi connection of the device. (requires root)
This command disables wifi connection of the device from the command line.
Screen recording
You can record the display of the device (running Android 4.4 or higher) with the help of screenrecord command. Here’s an example:
You can also specify quality of the recording with the --bit-rate parameter.
pm (package manager)
“adb shell pm $command” performs actions on application packages installed on your device. To see the detailed help just type adb shell pm.
adb shell pm list packages lists all the installed packages (apps).
adb shell pm uninstall $packagename uninstalls the specified package.
am (activity manager)
I am going to show you how to dump heap of a running android application and analyze the heap using Eclipse Memory Analyser.
First start the activity you want to monitor. In my case I am starting a game that we developed at Peak Games whose package name is net.peakgames.mobile.spades.android.
I need to find the process id of the application that I just started.
Process id of the application is 8196. I am going to dump the heap of this process to a file on the sdcard, copy the dump file to my computer and convert it to standart file format that a profiler (in our case Eclipse Memory Analyser) can parse and display with the hprof-conv tool.
Here is a screenshot of the heap dump opened with Eclipse Memory Analyzer Tool.