Some Useful Android Debug Bridge Commands

As I mentioned in a previous post, the Android Debug Bridge is a hugely useful command line tool which installs with the Android SDK, to the ‘platform-tools’ directory.

If your doing any development or testing on Android devices, this is a must to have installed on your machine. I recommend adding it to your Windows PATH variable, as once you begin to use it, you’ll find yourself coming back to it more and more.

In this post, I’ll outline some of the most useful commands I’ve been using in my interactions with Android so far. First off, ensure you have an Android device connected to your machine, or an emulator running.

adb provides a command for determining what Android devices are detected to your machine, ‘adb devices‘:

adb devices command

Use the above command to ensure that adb detects your device or emulator. For example, it may not detect a physical device if you don’t have the correct USB drivers installed.

Here are some of the other commands that should prove useful to you when working with Android devices. Note that for some of these commands to work, you will need to a rooted Android device.

Install an APK file

adb install path_to_apk_file

Uninstall an APK file

adb uninstall com.myapp.main

View the device log buffers

adb logcat

Switch locale on the device (to German in this example)

adb shell “su -c ‘setprop persist.sys.language de; setprop persist.sys.country de; stop; sleep 5; start’

Start intent e.g. your applications main Activity

adb shell am start -a android.intent.action.MAIN -n com.myapp.main/.activities.MainActivity

Run all Instrumentation tests in a Java class against an application

adb shell instrument -e class com.myapp.tests.UITests -w com.myapp.test/android.test.InstrumentationTestRunner

Get a dump of the devices configuration (useful to include in bug reports)

adb bugreport

These are the commands I’ve found most useful when working with Android so far, view all available commands by typing adb -h from the command line.

Happy New Year.