ADB ( Android Debug Bridge) is a very versatile command-line tool which helps you to communicate with your device. The ADB command helps to facilitate a variety of device action like debugging and installing apps which provide access to a Unix shell that you can use to run different commands on your device and it is also included in the Android SDK platform-tools package.
This is a client-server program which consists of three components namely:
1. A Client is that which sends commands. A client helps your device to work on your development machine and you can also input a client from a command-line terminal by issuing an and command.
2. A daemon also is known as (adbd), which works commands on your device. The daemon operates as a background process on every device.
3. A Server which helps to manage communication the daemon and the client. The server works as a background process on the development machine.
Related: How to use Revo Uninstaller
How it operates
When an ADB client is startup, the client first checks if there is an ADB server process which is running already. And if there is none, it begins the server process. When this server process starts, it joins to local TCP port 5037 and checks for commands that are sent from ADB clients, and all ADB clients make use of port 5037 to be able to communicate with the ADB server.
The ADB server then sets up many connections to all the running devices. It finds emulators by scanning through odd-numbered ports from the range of 5555 up to 5585, and the range was used first by the 16 emulators. This is where the server finds an ADB daemon which sets up a connection to that port.
Note: Each emulator makes use of a pair of sequential ports – an even-numbered port for an odd-numbered and console connections port for ADB connections. Examples are listed below:
- Emulator 1, console: 5553
- Emulator 1, ADB: 5554
- Emulator 2, console: 5555
- Emulator 2, ADB: 5556, etc…
The emulator which is connected to ADB on port 5554 is the same as the emulator whose console listens on port 5553.
Immediately the server has set up connections to all the devices, then you can use ADB commands in accessing those devices. This is because the server handles commands from multiple adb clients and manages connection s to devices. Which means you can control any device from a script or from any client.
Sending commands to a specific device
When multiple devices are running same time, then you must specify the device in which you are issuing the ADB command to the device. And to specify the target, you will make use of the devices command in order to obtain the serial number of the target. Immediately you have the serial number, you will use the -s option along with the ADB commands to specify the serial number. If you wish to issue many ADB commands, but instead, you can set the $ANDROID_SERIAL environment able to contain the serial number. But if you use both -s and $ANDROID_SERIAL, -s will override $ANDROID_SERIAL.
The example below shows the list of attached devices which is obtained, and next to the serial number of one of the devices from the devices is used to install helloWorld.apk on that device.
$ adb devices
List of devices attached
emulator -5553 device
emulator -5554 device
$ adb -s emulator -5554 install h
But note that if you are to issue a command without specifying a target device when other devices are available, the ADB command will generate an error. And if you have multiple devices that are available, but then only one is an emulator, you are to use -e option to send the ADB commands to the emulator. And so also if there are multiple devices but just one hardware device is attached, then you will use -d option to send commands to the hardware device.