1. 什么是adb
在SDK的Tools文件夹下包含着Android模拟器操作的重要命令ADB,ADB的全称为Android Debug Bridge,就是调试桥的作用。借助这个工具,我们可以管理设备或手机模拟器的状态 ,还可以进行以下的操作:
(1)快速更新设备或手机模拟器中的代码,如应用或Android系统升级;
(2)在设备上运行Shell命令;
(3)管理设备或手机模拟器上的预定端口;
(4)在设备或手机模拟器上复制或粘贴文件。
官网如下说:
Android Debug Bridge (adb) is a versatile command line tool that lets you communicate with an emulator instance or connected Android-powered device. It is a client-server program that includes three components:
- A client, which runs on your development machine. You can invoke a client from a shell by issuing an adb command. Other Android tools such as the ADT plugin and DDMS also create adb clients.
- A server, which runs as a background process on your development machine. The server manages communication between the client and the adb daemon running on an emulator or device.
- A daemon, which runs as a background process on each emulator or device instance.
You can find the adb
tool in <sdk>/platform-tools/
.
When you start an adb client, 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 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. For example:
Emulator 1, console: 5554
Emulator 1, adb: 5555
Emulator 2, console: 5556
Emulator 2, adb: 5557
and so on...
As shown, the emulator instance connected to adb on port 5555 is the same as the instance whose console listens on port 5554.
Once the server has set up connections to all emulator instances, you can use adb commands to access those instances. Because the server manages connections to emulator/device instances and handles commands from multiple adb clients, you can control any emulator/device instance from any client (or from a script).
2. 启动adb
我使用adb安装apk时,提示:
adb server is out of date. killing... ADB server didn‘t ACK * failed to start daemon *
原因上,电脑上安装的手机助手占用了adb的端口5037,所以adb启动不起来。如果可以退出手机助手,且插上手机后助手也不会霸占adb的端口,倒是可以保留。无奈,我PC上的手机助手做不到,我只能卸之。卸载后就OK了,命令行下adb操作就能启动adb server了。如果需要安装ios包,可以使用itools。试用了下,不会引起以上问题。
使用adb时,需开启android的debug模式。