Android Debug Bridge (ADB) command scripting

The Android Debug Bridge (ADB) is a useful tool for testing and debugging, though it can be cumbersome to use given its broad set of options. For example, testing an app might require frequent authentication, and just sending the username with adb looks like this:

Command aliases can simplify this. In bash, these can be added to the startup script, such as .bashrc:

Now the username can be passed by simply typing:

Windows users can do something similar using Doskey.

The password could be sent using a similar alias:

Since other text might be sent, and those aliases can be chained together, you could setup the following:

Next, add in some keyevents for navigating between the fields:

Now, the whole login flow can be performed using a single command, such as applogin:

This can be handy for simple and frequent app interaction while testing. I use scripts such as these to navigate through initial activities during a fresh app launch to get me to the point where I need to test or debug quickly.

A similar approach to all of this is to use monkeyrunner, or continuing down that route, testing using something like calabash, but for something quick, I find that this fits the bill.

Here is a larger set of adb option aliases, comprising my basic day to day needs:



Do you find this sort of work interesting? Do you love quaint Bucks County Pennsylvania? Are you an amazing Android Developer? Then we would love to hear from you!

Android Image Credit: Copyright Pinada, CC BY-ND 3.0

Leave a Reply

Your email address will not be published. Required fields are marked *