Android Debug Bridge (ADB)
The Android-Debug-Bridge (abbreviated as adb) is a software-interface for the android system, which can be used to connect an android device with a computer using an USB cable or a wireless connection. It can be used to execute commands on the phone or transfer data between the device and the computer.
The tool is part of the Android SDK (Android Software Development Kit) and is located in the subdirectory platform-tools. In previous versions of the SDK it was located in the subdirectory tools. Since January 2017, Google also provides the package in a separate, unbundled downloadable package with all other platform-tools, in which also the ADB and fastboot is included. The user now does not need to download the complete SDK just for the ADB and/or fastboot anymore. The download link is provided on the Android-Developer website.
What is ADB?
The Android Debug Bridge is a software interface between the device and the local computer, which allows the direct communication of both components. This includes the possibility to transfer files from one component to the other one, as well as executing commands from the computer on the connected device. The ADB can be used through a command line windows, terminal/shell in Linux-based systems, a command line (cmd) for Windows. There's no official graphical user interface for now.
The main advantage is to execute commands on the phone directly out of the computer, without any direct user interaction to the phone, which makes especially debugging a lot easier.
Apart from the possibility to connect a phone for using ADB using the usb cable (which was, for a long time, the only possible way), there's also the possibility to connect to the ADB daemon on the device using a tcp connection, which also includes the WiFi network.
In the following list you find some important commands, which you may need more often when working with the adb. If you want to view the help and a complete list of adb commands of the version you're using, just type the following command and hit return:
Show connected devices
Lists connected and available devices (only devices which have USB-Debugging enabled)
If there's an output something like this:
List of devices attached
there're most likely no devices connected, or there're no USB drivers installed (correctly) Does the output look like:
List of devices attached ???????????? no permissions
you, if you're using Windows, most likely need to write the Vendor ID of the device manufacturer (which can be found in the device manager) into this file (the format is: 0xZZZZ, where Z is a hexadecimal number from 0 to F):
The important thing is, that the vendor ID is written as it's own line in this file. When using Linux, the file can be found in the home directory of the current user in the hidden directory .android. The Vendor ID can be found with the command lsusb.
- From the device to the computer:
adb pull /pfad/am/handy.txt /pfad/am/computer.txt
- From the computer to the device:
adb push /pfad/am/computer.txt /pfad/am/handy.txt
You can install apps on the device. However, this requires the APK file to be present on the local computer (the user also needs to be able to access this file):
adb install /pfad/zur/datei/anwendung.apk
You can also show the system log using adb:
Sometimes it's useful to write (pipe) the output/the system log to a separate file (however, this is the default behavior of the system and not a special function of the ADB):
adb logcat > datei.txt
Open an interactive shell
To execute commands on the android device, you can use the following command. It will, if called without any arguments, open an interactive shell on the device, which is disaplayed in your console/terminal window. If you pass a string as an argument to the command, it will be executed on the device as a command for the device and the shell will be closed, once the command was executed.
Installation and setting the adb as a system environment variable in Windows
To avoid the need to navigate to the directory where the adb is located in each time you want to use the adb, you can add the directory to the PATH environment variable of your WIndows sytsem. That allows you to use adb commands in a command line windows, no matter where on the system you currently are. If you're using Windows 7 (it's slightly different on future versions of Windows, but basically the same) you can follow these steps:
- Control Panel
- System and security
- Advanced System settings
- Environment variables
Afterwards look for the Path variable in the System variables section and add the path to the platform-toolsdirectory on the system. The path needs to be absolute (not relative) and needs to be separated from the current value using a semicolon (;) (take a look to the image).
If you now open a new command line window at any directory on your computer, you should get a list of adb commands when you just type:
On most big Linux distirbutions, there's an adb and fastboot package, e.g.:
|openSUSE, Fedora, Arch Linux||android-tools|
|Slackware||android-tools (as aSlackBuild)|
On other distributions you can look in your packet manager for a package named android or adb and install the corresponding one. If there's no package, you can download the separate platform-tools package (see the introduction section) and put it somewhere. If you also want to use adb (and maybe fastboot) from anywhere in your system, you can symlink the binaries to the /bin directory:
ln -s /path/to/android/platform-tools/adb /bin/adb
ln -s /path/to/android/platform-tools/fastboot /bin/fastboot
- ↑ Dokumentation zu ADB (englisch)
- ↑ Google makes ADB, fastboot, and other platform tools available without full SDK or Android Studio download.
- ↑ How to get ADB and Fastboot utilities without installing the Android SDK. 5.
- ↑ Download ADB And Fastboot Tools Without SDK Or Android Studio, Here's How | Redmond Pie. 6.
- ↑ Google makes ADB and fastboot available without Android Studio or SDK. 6.