What is ADB? How to Install ADB?
Android Debug Bridge is often mentioned in the Android community. The tool helps Android developers manage emulators or connected devices via the command line. ADB is a part of Android SDK – you can find the tool in the platform-tools directory.
Managing ADB is not easy, as there are dozens of commands to remember. To know how to install and manage Android Debug Bridge, follow along with this post. You will find out how the tool works, what the most useful commands are, along with efficiency-boosting ADB usage tips.
What is ADB?
Android Debug Bridge, as the name suggests, is commonly used in the debugging process. By accessing the Unit shell of a device or an emulator, the tool connects a developer with a physical or a virtual smartphone and makes the testing process fully controlled and more efficient.
ADB consists both of client and server components. Here are three elements that comprise the tool.
- A client is in charge of processing and sending commands. The ADB client is installed on a computer a developer is using for coding. To start a client, type adb in the command line.
- A daemon (in short, adbd) is responsible for executing commands on an emulator or a different device. The tool usually runs in the background mode.
- A server is responsible for connecting to devices and transferring data from one to another. Like the client, the server is a part of the machine a tech team uses for coding.
How Does ADB Work?
Before running the ADB client, developers need to set up daemons on a local TCP port, as well as a server. In the command line, you will see the following message:
*daemon not running. Starting it now on port 5037 *daemon started successfully.
Once the daemon is running, ADB will rely on the TCP port for commands. The ADB will then connect the computer with the attached devices or emulators. To connect your Android device and the debugging bridge successfully, confirm an authorization request on a smartphone.
Viewing all attached devices
To see the list of devices attached to the ADB, run the adb devices command. You will see the list of emulators and physical smartphones that are connected to the tool. The type and the number of the device will be displayed as its id (e.g. emulator-5556).
Four-digit numbers in the device numbers are the ports scanned by the client. They can fall into the range between 5555 to 5585. Keep in mind that each console or emulator uses a pair of ports to connect with the ADB. For example, if there’s an emulator-5556, the next line in the pair will be adb-5557.
As soon as you connected a device to ADB, you can freely manage it via a client.
Enabling ADB debugging on a smartphone
To allow a smartphone to connect to Android Debugging Bridge, enable USB debugging in the device’s settings. You can find it in the Developers options tab – that one is tricky to find.
Here’s how you can display Developer Options:
- Take a Settings -> About phone path
- Choose Build number for seven times;
- Go back to About Phone to find the Developers Options tab in the bottom of the screen.
By running the adb_devices command, you will enable USB debugging and grant authorization for ADB connection.
Note: on some devices, the tab Development Options might have a different name.
Transfer files between development and testing devices
During the debugging process, it’s common for software developers to exchange files between a computer and an emulator or a connected smartphone. You can enable such a transfer via ADB – here’s how.
Run the following command in the command line:
adb push [file name] [file path].
Installing apps on connected devices
ADB allows developers to install APK files on smartphones remotely. For that, use adb install, as shown in the example below:
adb install [filename.apk].
Uninstalling apps on connected devices
Similarly, you can remove an application from a smartphone if it’s no longer needed. Run
adb uninstall [application package.name].
Pay attention that, unlike in the previous case, to delete applications, a developer has to specify the package, not just the name of the software.
Rebooting devices via a command line
ADB allows developers to reboot emulators and connected smartphones by running a single command. Enter adb reboot to initiate the process. To use a bootloader for device reboot, run adb reboot-bootloader.
Applying commands on selected devices
In case you work with multiple devices simultaneously, specify which device needs to respond to a given command. Here’s how it look in the Android Debugging Bridge client:
adb-s emulator[port name] [command name].
Getting inside the shell
Entering the emulator’s shell allows developers to give specific commands to a device without having to specify its name every time. adb shell grants access to a smartphone’s shell.
Display recording and taking screenshots
ADB comes with multiple useful features, such as capturing and recording the screen of the emulator via the command line. To take a screenshot of a device’s screen, type in the following command:
adb shell screencard/sdcard/[file name under which the screenshot will be saved].
You will need to run a separate command to transfer the screenshot to a PC:
adb pull /sd card/[filename].
To record the display of the smartphone, you can enter a highly specific command, stating the desired length and the bitrate. Here’s the full look of the command in the client:
adb shell screenrecord - time-limit [time] [bitrate] /sdcard/[filename].
Similarly to the screenshot, you can retrieve the video using adb pull. There are many more adb commands that are useful for testing. You can access the full list at Android Debug Bridge Documentation.
How to Install ADB
Before running the Android Debug Bridge, you will need to install the client on your computer. Here’s how to download the file for all the most common operating systems.
- Download the official installation file;
- Move the contents of the ZIP to a more convenient path (depends on personal preferences);
- Open the command prompt and establish the chosen directory as the ADB directory by pressing Shift+Right click and choosing Open PowerShell/command prompt here).
- Connect a smartphone to the ADB;
adb devicesto start the daemon;
- Request adb authorization on a smartphone.
- Download the official file
- Move the file to an accessible directory;
- Open the terminal;
- Connect ADB to the smartphone;
adb devicesin the terminal
- Allow the connection on the smartphone.
- Download ADB for Linux
- Extract all files and move them to a new folder
cd path /to/extracted/folderin the terminal
- Connect the phone to the adb
adb devicesin the Terminal window
- Grant ADB access to the smartphone.