官术网_书友最值得收藏!

Android Debug Bridge

Android Debug Bridge (adb) is a tool used to establish communication between the development environment and a virtual device or the connected Android device. It is a client-server command-line program, which works on three elements:

  • Client on the development machine: Works as the client, which can be invoked by adb commands. Other Android tools such as the ADT plugin and DDMS also create adb clients.
  • Daemon: A background process that runs in the background on each emulator or device instance.
  • Server on the development machine: This is a background process that runs on the development machine and manages the communication between the client and server.

On starting adb, the client first checks whether there is an adb server process already running. If there isn't, it starts the server process. When the server starts, it binds to the local TCP port 5037 and listens for commands sent from adb clients—all adb clients use port 5037 to communicate with the adb server.

The server then sets up connections to all running emulator/device instances. It locates emulator/device instances by scanning odd-numbered ports in the range 5555 to 5585, the range used by emulators/devices. Where the server finds an adb daemon, it sets up a connection to that port. Note that each emulator/device instance acquires a pair of sequential ports—an even-numbered port for console connections and an odd-numbered port for adb connections.

Once the server has set up connections to all emulator instances, the developer can use adb commands to access those instances. Because the server manages connections to emulator/device instances, and handles commands from multiple adb clients, the developer can control any emulator/device instance from any client (or from a script).

Using adb on an Android device

One of the first things to remember is to put the development device in the USB debugging mode. This can be done by navigating to Settings, tapping on Developer options, and checking the box named USB debugging for Android 5.0 and above (for other Android versions, refer to https://www.recovery-android.com/enable-usb-debugging-on-android.html). Without doing this, the development PC won't recognize the device.

The most important thing to know is simply how to get to the adb folder via the command line. This is done with the cd (change directory) command. So, if (on Windows) the SDK folder is called android-SDK, and it's in the root (c:) directory, you can enter the following command:

cd c:/android-SDK

Then, to get into the adb folder, use this:

cd platform-tools

At this point, the prompt will say this:

C:\android-SDK\platform-tools>

Now the developer can connect the device, and test the adb connection, after locating and installing the drivers for a particular device:

adb devices

If everything is set up properly, there should be a list of devices attached. The phone or tablet will have a number assigned to it, so don't be surprised if it doesn't say "Droid Razr" or "Galaxy Nexus".

For average users, adb is more of a tool for basic hacking tasks than it is a task in itself. Unless the developers know what they are doing, they probably shouldn't go poking around too much without clear instructions. When rooting the device, knowing these basics can help save some time and let the developer be prepared in advance.

Beside the specific instructions to root a particular device, the next thing the developer needs will be the drivers for the phone or tablet.

The easiest way to do this is usually to simply Google search for the specific device plus drivers. So if the developer has a Droid Razr, he/she should search for Droid Razr Windows Drivers. This will almost always direct the developer to the best link.

Another option, which will only work for stock Android devices, is to download the USB drivers from the SDK. To do this, launch the SDK manager again. Go to the Available packages tab on the left, expand the Third party add-ons entry, and then expand the Google Inc. add-ons entry. Finally, check the entry for the Google USB Driver package.

Note that the USB driver package isn't compatible with OS X.

主站蜘蛛池模板: 包头市| 远安县| 明光市| 鄂托克旗| 沾化县| 岑巩县| 黄平县| 庆阳市| 澜沧| 呼玛县| 卢氏县| 蓝山县| 丹江口市| 白朗县| 合作市| 精河县| 福建省| 兰西县| 宕昌县| 陆丰市| 常德市| 博湖县| 长武县| 合江县| 微山县| 林口县| 临泽县| 永新县| 鹿泉市| 平顶山市| 西藏| 玉山县| 杂多县| 永泰县| 兴义市| 庄河市| 凤台县| 仁化县| 天气| 武夷山市| 平江县|