- 一个客户,你的开发机器上运行。您可以调用客户端通过发出一个adb shell。其他Android工具也如ADT插件和DDMS创建 adb client。
- 一个服务器,它作为后台进程运行在您的开发机器上。服务器管理客户端之间的通信和adb进程运行在模拟器或设备。
- 一个守护进程,它作为后台进程运行在每个模拟器或设备的实例。
- 模拟器控制台1:5554
- 模拟器1,adb:5555
- 模拟器控制台2:5556
- 模拟器2,adb:5557 等等……
Category | Command | Description | Comments |
---|---|---|---|
Target Device | -d |
Direct an adb command to the only attached USB device.
在
唯一
连接USB设备
运行
一个adb命令
。
| Returns an error if more than one USB device is attached. |
-e | 在唯一连接的模拟器运行一个adb命令。 | Returns an error if more than one emulator instance is running. | |
-s <serialNumber> | 在指定模拟器/设备实例直接运行一个adb命令,通过其adb-assigned序列号(如“ emulator- 5556”)。 | 用法见下文 | |
General | devices | 打印所有连接模拟器/设备实例的列表。 | 用法见下文 |
help | 打印所有adb命令的列表。 | ||
version | 打印所有adb版本号。 | ||
Debug | logcat [option] [filter-specs] | 将日志数据打印到屏幕上。. | |
bugreport | 打印dumpsys , dumpstate , 和 logcat 数据到屏幕上, 为了报告BUG | ||
jdwp | Prints a list of available JDWP processes on a given device.(mark不太懂) |
你可以使用
forward jdwp:<pid>
port-forwarding specification to connect to a specific JDWP process. For example:
adb forward tcp:8000 jdwp:472 jdb -attach localhost:8000 | |
Data | install <path-to-apk> | 导入一个apk项目(specified as a full path to an .apk file) to an emulator/device. | |
pull <remote> <local> | 从模拟器/设备导出(复制)一个指定文件到你的电脑 | ||
push <local> <remote> | 从你的电脑导出(复制)一个指定文件到你的模拟器/设备 | ||
Ports and Networking | forward <local> <remote> |
Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance.
将套接字连接从一个指定的本地端口转发到指定
模拟器/设备实例
的远程端口。
| Port specifications can use these schemes:
|
ppp <tty> [parm]... | Run PPP over USB.
Note that you should not automatically start a PPP connection. | ||
Scripting | get-serialno | Prints the adb instance serial number string. | See Querying for Emulator/Device Instancesfor more information. |
get-state | Prints the adb state of an emulator/device instance. | ||
wait-for-device | Blocks execution until the device is online — that is, until the instance state is device . | You can prepend this command to other adb commands, in which case adb will wait until the emulator/device instance is connected before issuing the other commands. Here's an example: adb wait-for-device shell getpropNote that this command does not cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system. As an example, the install requires the Android package manager, which is available only after the system is fully booted. A command such as adb wait-for-device install <app>.apkwould issue the install command as soon as the emulator or device instance connected to the adb server, but before the Android system was fully booted, so it would result in an error. | |
Server | start-server | Checks whether the adb server process is running and starts it, if not. | |
kill-server | Terminates the adb server process. | ||
Shell | shell | Starts a remote shell in the target emulator/device instance. | See ADB Shell Commands for more information. |
shell [shellCommand] | Issues a shell command in the target emulator/device instance and then exits the remote shell. |
- 序列号——一个由adb用来唯一地标识一个模拟器/设备实例的控制台端口号码的字符串。编号的格式是<type> - < consolePort >。这里有一个例子序列号:emulator- 5554
- 实例的状态,连接状态可能是下列之一:
-
-
offline
— the instance is not connected to adb or is not responding离线状态:实例例没有连接到adb或者没有响应.device
— the instance is now connected to the adb server. Note that this state does not imply that the Android system is fully booted and operational, since the instance connects to adb while the system is still booting. However, after boot-up, this is the normal operational state of an emulator/device instance启动状态,可以进行各种操作.no device
— there is no emulator/device connected.没有模拟器/设备连接
-
-
每个实例的输出格式如下:
[serialNumber] [state]
Here's an example showing the
devices
command and its output:adb devices
List of devices attached
emulator-5554 device
emulator-5556 device
emulator-5558 device
-s
option in the commands. The usage for the
-s
option is:
adb -s <serialNumber> <command>
As shown, you specify the target instance for a command using its adb-assigned serial number. You can use the devices
command to obtain the serial numbers of running emulator/device instances. For example:
adb -s emulator-5556 install helloWorld.apk
You can use adb to copy an application from your development computer and install it on an emulator/device instance. To do so, use the install
command. With the command, you must specify the path to the .apk file that you want to install:
forward
command to set up arbitrary port forwarding — forwarding of requests on a specific host port to a different port on an emulator/device instance. Here's how you would set up forwarding of host port 6100 to emulator/device port 7100:
adb forward tcp:6100 tcp:7100
pull
和 push去复制文件
to and from an emulator/device instance. 与
install命令不同
, 这是复制一个APK文件到指定位置, the
pull
and
push
命令让你从任意目录和文件复制到模拟器/设备实例中任何位置。
To copy a file or directory (and its sub-directories) from the emulator or device, use
adb pull <remote> <local>
To copy a file or directory (and its sub-directories) to the emulator or device, use
adb push <local> <remote>
In the commands, <local>
and <remote>
refer to the paths to the target files/directory on your development machine (local) and on the emulator/device instance (remote). For example:
In some cases, you might need to terminate the adb server process and then restart it to resolve the problem (e.g., if adb does not respond to a command).
kill-server
command. You can then restart the server by issuing any other adb command.
-
把你的Android设备和adb主机连接到共同的wifi网络访问。我们已经发现,并不是所有的接入点都合适,您可能需要使用一个接入点的防火墙支持配置adb。Note: 如果你正试图连接到一个可穿戴装置,迫使其关闭wi - fi连接的蓝牙手机连接到它。
- 将设备连接到主机的USB接口
- 设置目标设备在端口5555上监听TCP / IP连接.
$ adb tcpip 5555
- 将目标设备断开连接USB接口.
- 找到设备ip地址. For example, on a Nexus device, you can find the IP address at Settings >About tablet (or About phone) > Status > IP address. Or, on an Android Wear device, you can find the IP address atSettings > Wi-Fi Settings > Advanced > IP address.
- 连接到设备,确定它的IP地址
$ adb connect <device-ip-address>
- 确认你的主机连接到目标设备:
$ adb devices List of devices attached <device-ip-address>:5555 device
You're now good to go!
If the adb connection is ever lost:
- Make sure that your host is still connected to the same Wi-Fi network your Android device is.
- Reconnect by executing the "adb connect" step again.
- Or if that doesn't work, reset your adb host:
adb kill-server
and then start over from the beginning.
附上无线调试图片 挺好玩的 还有更多adbshell 通过shell对手机进行裁图,录制屏幕 很有用的
shell@ $ screenrecord -- verbose / sdcard / demo . mp4
( press Ctrl - C to stop )
shell@ $ exit
$ adb pull / sdcard / demo . mp4
screenrecord
options
Options | Description |
---|---|
--help | Displays command syntax and options |
--size <WIDTHxHEIGHT> | Sets the video size: 1280x720 . The default value is the device's native display resolution (if supported), 1280x720 if not. For best results, use a size supported by your device's Advanced Video Coding (AVC) encoder. |
--bit-rate <RATE> | Sets the video bit rate for the video, in megabits per second. The default value is 4Mbps. You can increase the bit rate to improve video quality, but doing so results in larger movie files. The following example sets the recording bit rate to 6Mbps: screenrecord --bit-rate 6000000 /sdcard/demo.mp4 |
--time-limit <TIME> | Sets the maximum recording time, in seconds. The default and maximum value is 180 (3 minutes). |
--rotate | Rotates the output 90 degrees. This feature is experimental. |
--verbose | Displays log information on the command-line screen. If you do not set this option, the utility does not display any information while running. |
The screencap
command is a shell utility for taking a screenshot of a device display. While in a shell, the syntax is:
screencap <filename>
To use the screencap
from the command line, type the following:
$ adb shell screencap /sdcard/screen.png
Here's an example screenshot session, using the adb shell to capture the screenshot and the pull
command to download the file from the device:
shell@ $ screencap / sdcard / screen . png
shell@ $ exit
$ adb pull / sdcard / screen . png
下面的了解一下 挺好玩的
利用PackageManager写shell操作
pm
) tool to perform actions and queries on application packages installed on the device. While in a shell, the syntax is:
pm <command>
You can also issue a package manager command directly from adb without entering a remote shell. For example:
adb shell pm uninstall com.example.MyApp
Table 3. Available package manager commands.
Command | Description |
---|---|
list packages [options] <FILTER> | Prints all packages, optionally only those whose package name contains the text in <FILTER> . Options:
|
list permission-groups | Prints all known permission groups. |
list permissions [options] <GROUP> | Prints all known permissions, optionally only those in<GROUP> . Options:
|
list instrumentation | List all test packages. Options:
|
list features | Prints all features of the system. |
list libraries | Prints all the libraries supported by the current device. |
list users | Prints all users on the system. |
path <PACKAGE> | Print the path to the APK of the given <PACKAGE> . |
install [options] <PATH> | Installs a package (specified by <PATH> ) to the system. Options:
|
uninstall [options] <PACKAGE> | Removes a package from the system. Options:
|
clear <PACKAGE> | Deletes all data associated with a package. |
enable <PACKAGE_OR_COMPONENT> | Enable the given package or component (written as "package/class"). |
disable <PACKAGE_OR_COMPONENT> | Disable the given package or component (written as "package/class"). |
disable-user [options] <PACKAGE_OR_COMPONENT> | Options:
|
grant <PACKAGE_NAME> <PERMISSION> | Grant a permission to an app. On devices running Android 6.0 (API level 23) and higher, may be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app. |
revoke <PACKAGE_NAME> <PERMISSION> | Revoke a permission from an app. On devices running Android 6.0 (API level 23) and higher, may be any permission declared in the app manifest. On devices running Android 5.1 (API level 22) and lower, must be an optional permission defined by the app. |
set-install-location <LOCATION> | Changes the default install location. Location values:
Note: This is only intended for debugging; using this can cause applications to break and other undesireable behavior. |
get-install-location | Returns the current install location. Return values:
|
set-permission-enforced <PERMISSION> [true|false] | Specifies whether the given permission should be enforced. |
trim-caches <DESIRED_FREE_SPACE> | Trim cache files to reach the given free space. |
create-user <USER_NAME> | Create a new user with the given <USER_NAME> , printing the new user identifier of the user. |
remove-user <USER_ID> | Remove the user with the given <USER_IDENTIFIER> , deleting all data associated with that user |
get-max-users | Prints the maximum number of users supported by the device. |
Within an adb shell, you can issue commands with the activity manager (am
) tool to perform various system actions, such as start an activity, force-stop a process, broadcast an intent, modify the device screen properties, and more. While in a shell, the syntax is:
am <command>
You can also issue an activity manager command directly from adb without entering a remote shell. For example:
adb shell am start -a android.intent.action.VIEW
Table 2. Available activity manager commands
Command | Description |
---|---|
start [options] <INTENT>
(选项里面没有-a 经试验就是打开一个activity)
| Start an Activity specified by <INTENT> . See the Specification for <INTENT> arguments. Options are:
|
startservice [options] <INTENT> | Start the Service specified by <INTENT> . See the Specification for <INTENT> arguments. Options are:
|
force-stop <PACKAGE> | Force stop everything associated with <PACKAGE> (the app's package name). |
kill [options] <PACKAGE> | Kill all processes associated with <PACKAGE> (the app's package name). This command kills only processes that are safe to kill and that will not impact the user experience. Options are:
|
kill-all | Kill all background processes. |
broadcast [options] <INTENT> | Issue a broadcast intent. See the Specification for <INTENT> arguments. Options are:
|
instrument [options] <COMPONENT> | Start monitoring with an Instrumentation instance. Typically the target <COMPONENT> is the form <TEST_PACKAGE>/<RUNNER_CLASS> . Options are:
|
profile start <PROCESS> <FILE> | Start profiler on <PROCESS> , write results to <FILE> . |
profile stop <PROCESS> | Stop profiler on <PROCESS> . |
dumpheap [options] <PROCESS> <FILE> | Dump the heap of <PROCESS> , write to <FILE> . Options are:
|
set-debug-app [options] <PACKAGE> | Set application <PACKAGE> to debug. Options are:
|
clear-debug-app | Clear the package previous set for debugging with set-debug-app . |
monitor [options] | Start monitoring for crashes or ANRs. Options are:
|
screen-compat [on|off] <PACKAGE> | Control screen compatibility mode of <PACKAGE> . |
display-size [reset|<WxH>] | Override emulator/device display size. This command is helpful for testing your app across different screen sizes by mimicking a small screen resolution using a device with a large screen, and vice versa. Example: |
display-density <dpi> | Override emulator/device display density. This command is helpful for testing your app across different screen densities on high-density screen environment using a low density screen, and vice versa. Example: |
to-uri <INTENT> | Print the given intent specification as a URI. See the Specification for <INTENT> arguments. |
to-intent-uri <INTENT> | Print the given intent specification as an intent: URI. See the Specification for <INTENT> arguments. |