Android Debug Bridge (adb) is a multi-function command that allows you to communicate with a simulator or android device. It is a client-server program that contains three components:
1. Run the adb client on your development machine. You can use the adb command in the shell to call an adb client. In addition, both the ADT plug-in and DDMS use the adb client function.
2. An adb server running on your development machine. The adb server is used to maintain communications between the adb client and the adb daemon.
3. adb daemon running on the simulator or android device background.
The adb tool is in the <sdk>/platform-tools/directory.
When you start an adb client, the adb client checks whether the development machine has run the adb server process. If not, the client starts the adb server. After the adb server is started, the adb server binds the local TCP5037 port and then listens to the adb Command sent from the adb client. All adb clients communicate with the adb server through port 5037.
The adb server must be connected to all simulators or android devices running on the development machine. It searches for simulators or android devices by scanning all the odd ports between 5555-5585. The adb server scans each adb daemon and establishes a binding with the relevant port. Since each simulator or android device obtains an ordered port (an even console connection port and an odd adb connection port) as follows: Emulator1, console: 5554 Emulator1, adb: 5555; emulator2, console: 5556 Emulator2, adb: 5557; so on. Similarly, if the product that a simulator connects to adb is 5555, the port connecting to the console is 5554.
After the adb server is connected to a simulator or android device, you can use the adb command (or script) to access the simulator or android device.
Note: When connecting to an android device later than android 4.2.2, the system will send a dialog box asking whether to accept an RSA key for debugging on the development machine. This security mechanism protects user devices and prevents adb commands from being executed. Unless you can unlock the android device and confirm the ask dialog box, of course, this is possible in adb1.0.31 or later versions (SDK Platform-tools16.0.1 or later.
You can run the adb command on the development machine through command lines or scripts. For example:
Adb [-d |-e |-s <serialNumber>] <command> if your development machine runs only one simulator or android device, the adb command is sent to the simulator or android device by default for execution. If multiple simulators or android devices are running, you must use the-d,-e, or-s parameters to specify the simulator or android device that executes the adb command. The usage of related parameters or commands is as follows:
-D: Direct the adb command to the android device on the development machine. If multiple android devices are connected to the development machine, an error is returned.
-E: points the adb command to a unique simulator.
-S <serialNumber>: directs the adb command to a specific android device (for example, emulator-5556)
Devices: Query all android devices connected to the development machine.
Help: help command.
Version: version query.
Logcat [option] [filter-specs]: prints log information.
Jdwp: A list of valid JDWP processes.
Install <path-to-apk>: install apk to the specified device.
Pull <remote> <local>: copy the file to a specified location on the development machine.
Push <local> <remote>: copy the file to the specified android device.