Useful ADB Commands

If you are developing Android apps, using the Android Debug Bridge tool (ADB) may sometimes be necessary, or could save you a lot of time.

With ADB you can install/uninstall apps, forward ports, push/pull files to your device, remotely connect to SQLite databases on your device, record the device screen, and more. See the link at the bottom for a full reference.

Setting up the ADB tool

The ADB tool comes with the Android SDK, and you can find the adb tool in <sdk folder>/platform-tools/.

Add the ADB tool to your shells path:

export PATH="$PATH:/Users/username/dev/androidsdk/platform-tools"  

Or just add this line to your .bashrc file (or .zshrc if you are using zshell).

  • Connect your device to your computer to run these commands.
  • Also, you must enable USB debugging in the device system settings, under Developer options.

List connected devices

adb devices  

Installing/uninstalling Apps

Installing an app

adb install appname.apk  

And similarly for uninstalling:

adb uninstall  

Simulate App update

You can use this command to simulate an update of an existing app, if you want to test your upgrade scripts.

adb install -r appname.apk  

Sideloading new versions of Android early

You can use adb to update your Android device with OTA updates you can download from the internet.

See this post on sideloading OTA updates.

If you have a rooted device

If you have a rooted device you can do a bit more with the ADB tool, such as extracting app database files from the device:

  1. Open a terminal
  2. Run adb shell to get a shell.
  3. su to get root.
  4. Press 'Allow' on device
  5. chmod 777 /data /data/data /data/data/com.application.pacakage /data/data/com.application.pacakage/*
  6. Go to the DDMS view in Android Studio (or just run the program independently from the SDK folder)

You should now be able to browse files on the device.

You can do a lot more with the ADB tool, refer to the Android developer documentation:

comments powered by Disqus