How To Use Android Debug Bridge (ADB)

ADB is a powerful tool, it is abbreviation of Android Debug Bridge. It is located in %ANDROID_HOME%\platform-tools like C:\Users\Jerry\AppData\Local\Android\sdk\platform-tools. It provide a lot of useful sub commands for android developers to operate between android physical or virtual device and computer. It can be used to copy files, install app or execute Linux commands in android OS directly. This article will show you how to use it in detail.

ADB Commands Examples

1. List current running android devices.

  1. First you need to Enable USB debugging mode in your physical android device. You can click here to learn how to do this if you do not know.
  2. Connect it with PC using a USB line.
  3. Open dos window, and go to %ANDROID_HOME%\platform-tools directory.
  4. Type adb devices, click enter key.
  5. You can see there is a device listed in the console, it is just the connected physical phone.
    android usb debugging mode connected devices with pc list
  6. Launch Android Studio, click AVD manager icon in top tool bar.
    avd manager in the tool bar
  7. It will list all exist android virtual devices in a window as below.
    launch avd in avd list
  8. Click green button to launch an AVD.
  9. After the virtual device startup. Run adb devices command in dos window, you can see that both the physical device and the virtual device are listed in the window.
    adb devices list physical and vritual devices

2. Copy Files Between Computer And Physical Or Virtual Device.

With adb command, copy files between devices and computer is very easy. By default, adb command always copy files to the currently running device, but if there has more than one devices connected, when you run below command, it will prompt an error message like adb: error: failed to get feature set: more than one device/emulator. So you should only has one device connected with PC.

READ :   Android ADB Install / Uninstall App Examples

adb push file to multiple connected device error message

  1. adb push c:\windows-version.txt /sdcard/ : This will copy file c:\windows-version.txt to current connected device /sdcard/ directory.
    adb push file from pc to android device success
  2. Now you can check the file in your device to see whether it is there or not.
    adb push file from pc to android device check file in android device
  3. You may encounter error message during this process such as “This adb server’s $ADB_VENDOR_KEYS is not set“, just do as the after message suggests “Try ‘adb kill-server’ if that seems wrong. Otherwise check for a confirmation dialog on your device.” can resolve all the problems.
    adb push file error message and resolve methods
  4. adb pull /sdcard/roam.txt C:\WorkSpace : This command will pull files from android device to current PC C:\WorkSpace directory.

3. Open Shell Window In Android Device.

The kernel of android platform is Linux-based, and sometimes developers want to open shell window of android platform directly. This allows you to perform some common Linux commands in shell window, such as ls, mkdir, rm, etc. Below commands can achieve this.

  1. adb shell : This command will let you login to the device as a common user. When the shell opened, we can run cd /sdcard/, ls -l to see the file we just copied.
    adb shell command

4. Install or Uninstall APK File.

  1. adb install [-r -s] apk_file : This command will install apk_file. -r means reinstall this apk, -s means install apk in sd card.
  2. adb uninstall [-k] package : This command will uninstall apk package. -k means delete the app only but reserve app related settings data and cache.

For more adb command prarmeters, you can run adb -help to get help list of adb command. Or you can click here go to adb online help documents.

(Visited 1,751 times, 4 visits today)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.