配置环境变量
右键我的电脑 -> 属性 -> 高级 -> 环境变量 -> Path
在Path中添加Android SDK安装路径中 adb.exe 的路径,例如【\sdk\
platform-tools】
,注意用【;】分号隔开。
另外,最好也将【\sdk\
platforms】
目录添加进去。
常用ADB命令
查看设备
adb
devices
安装APP
adb
install
apk文件路径
卸载软件
adb
uninstall 软件包名
进入shell
adb
shell
回到根目录 cd /
回到上一级目录 cd ..
导入文件 adb push <本地路径> <手机路径>
导出文件 adb pull <手机路径> <本地路径>
获取权限 adb root
关闭adb adb kill-server
开启adb adb start-server
查看log adb logcat [-s 标签名]
选择指定的设备 adb –s <模拟器名称> (后面要选择执行的命令)
获取root权限 su[用户名,如root]
查看文件结构 ls
查看占用端口的进程 netstat -ano
全部命令
Android Debug Bridge version 1.0.32
Revision 09a0d98bebce-android
-a - directs adb to listen on all interfaces for a connection
-d - directs command to the only connected USB device
returns an error if more than one USB device is present.
-e - directs command to the only running emulator.
returns an error if more than one emulator is running.
-s <specific device> - directs command to the device or emulator with the given
serial number or qualifier. Overrides ANDROID_SERIAL
environment variable.
-p <product name or path> - simple product name like 'sooner', or
a relative/absolute path to a product
out directory like 'out/target/product/sooner'.
If -p is not specified, the ANDROID_PRODUCT_OUT
environment variable is used, which must
be an absolute path.
-H - Name of adb server host (default: localhost)
-P - Port of adb server (default: 5037)
devices [-l] - list all connected devices
('-l' will also list device qualifiers)
connect <host>[:<port>] - connect to a device via TCP/IP
Port 5555 is used by default if no port number is specified.
disconnect [<host>[:<port>]] - disconnect from a TCP/IP device.
Port 5555 is used by default if no port number is specified.
Using this command with no additional arguments
will disconnect from all connected TCP/IP devices.
device commands:
adb push [-p] <local> <remote>
- copy file/dir to device
('-p' to display the transfer progress)
adb pull [-p] [-a] <remote> [<local>]
- copy file/dir from device
('-p' to display the transfer progress)
('-a' means copy timestamp and mode)
adb sync [ <directory> ] - copy host->device only if changed
(-l means list but don't copy)
adb shell - run remote shell interactively
adb shell <command> - run remote shell command
adb emu <command> - run emulator console command
adb logcat [ <filter-spec> ] - View device log
adb forward --list - list all forward socket connections.
the format is a list of lines with the following format:
<serial> " " <local> " " <remote> "\n"
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)
adb forward --no-rebind <local> <remote>
- same as 'adb forward <local> <remote>' but fails
if <local> is already forwarded
adb forward --remove <local> - remove a specific forward socket connection
adb forward --remove-all - remove all forward socket connections
adb reverse --list - list all reverse socket connections from device
adb reverse <remote> <local> - reverse socket connections
reverse specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
adb reverse --norebind <remote> <local>
- same as 'adb reverse <remote> <local>' but fails
if <remote> is already reversed.
adb reverse --remove <remote>
- remove a specific reversed socket connection
adb reverse --remove-all - remove all reversed socket connections from device
adb jdwp - list PIDs of processes hosting a JDWP transport
adb install [-lrtsdg] <file>
- push this package file to the device and install it
(-l: forward lock application)
(-r: replace existing application)
(-t: allow test packages)
(-s: install application on sdcard)
(-d: allow version code downgrade)
(-g: grant all runtime permissions)
adb install-multiple [-lrtsdpg] <file...>
- push this package file to the device and install it
(-l: forward lock application)
(-r: replace existing application)
(-t: allow test packages)
(-s: install application on sdcard)
(-d: allow version code downgrade)
(-p: partial application install)
(-g: grant all runtime permissions)
adb uninstall [-k] <package> - remove this app package from the device
('-k' means keep the data and cache directories)
adb bugreport - return all information from the device
that should be included in a bug report.
adb backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
- write an archive of the device's data to <file>.
If no -f option is supplied then the data is written
to "backup.ab" in the current directory.
(-apk|-noapk enable/disable backup of the .apks themselves
in the archive; the default is noapk.)
(-obb|-noobb enable/disable backup of any installed apk expansion
(aka .obb) files associated with each application; the default
is noobb.)
(-shared|-noshared enable/disable backup of the device's
shared storage / SD card contents; the default is noshared.)
(-all means to back up all installed applications)
(-system|-nosystem toggles whether -all automatically includes
system applications; the default is to include system apps)
(<packages...> is the list of applications to be backed up. If
the -all or -shared flags are passed, then the package
list is optional. Applications explicitly given on the
command line will be included even if -nosystem would
ordinarily cause them to be omitted.)
adb restore <file> - restore device contents from the <file> backup archive
adb disable-verity - disable dm-verity checking on USERDEBUG builds
adb enable-verity - re-enable dm-verity checking on USERDEBUG builds
adb keygen <file> - generate adb public/private key. The private key is stored in <file>,
and the public key is stored in <file>.pub. Any existing files
are overwritten.
adb help - show this help message
adb version - show version num
scripting:
adb wait-for-device - block until device is online
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
adb get-state - prints: offline | bootloader | device
adb get-serialno - prints: <serial-number>
adb get-devpath - prints: <device-path>
adb remount - remounts the /system, /vendor (if present) and /oem (if present) partitions on the device read-write
adb reboot [bootloader|recovery]
- reboots the device, optionally into the bootloader or recovery program.
adb reboot sideload - reboots the device into the sideload mode in recovery program (adb root required).
adb reboot sideload-auto-reboot
- reboots into the sideload mode, then reboots automatically after the sideload regardless of the result.
adb sideload <file> - sideloads the given package
adb root - restarts the adbd daemon with root permissions
adb unroot - restarts the adbd daemon without root permissions
adb usb - restarts the adbd daemon listening on USB
adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port
networking:
adb ppp <tty> [parameters] - Run PPP over USB.
Note: you should not automatically start a PPP connection.
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
adb sync notes: adb sync [ <directory> ]
<localdir> can be interpreted in several ways:
- If <directory> is not specified, /system, /vendor (if present), /oem (if present) and /data partitions will be updated.
- If it is "system", "vendor", "oem" or "data", only the corresponding partition
is updated.
environment variables:
ADB_TRACE - Print debug information. A comma separated list of the following values
1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given.
ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.
x
1
Android Debug Bridge version 1.0.32
2
Revision 09a0d98bebce-android
3
4
-a - directs adb to listen on all interfaces for a connection
5
-d - directs command to the only connected USB device
6
returns an error if more than one USB device is present.
7
-e - directs command to the only running emulator.
8
returns an error if more than one emulator is running.
9
-s <specific device> - directs command to the device or emulator with the given
10
serial number or qualifier. Overrides ANDROID_SERIAL
11
environment variable.
12
-p <product name or path> - simple product name like 'sooner', or
13
a relative/absolute path to a product
14
out directory like 'out/target/product/sooner'.
15
If -p is not specified, the ANDROID_PRODUCT_OUT
16
environment variable is used, which must
17
be an absolute path.
18
-H - Name of adb server host (default: localhost)
19
-P - Port of adb server (default: 5037)
20
devices [-l] - list all connected devices
21
('-l' will also list device qualifiers)
22
connect <host>[:<port>] - connect to a device via TCP/IP
23
Port 5555 is used by default if no port number is specified.
24
disconnect [<host>[:<port>]] - disconnect from a TCP/IP device.
25
Port 5555 is used by default if no port number is specified.
26
Using this command with no additional arguments
27
will disconnect from all connected TCP/IP devices.
28
29
device commands:
30
adb push [-p] <local> <remote>
31
- copy file/dir to device
32
('-p' to display the transfer progress)
33
adb pull [-p] [-a] <remote> [<local>]
34
- copy file/dir from device
35
('-p' to display the transfer progress)
36
('-a' means copy timestamp and mode)
37
adb sync [ <directory> ] - copy host->device only if changed
38
(-l means list but don't copy)
39
adb shell - run remote shell interactively
40
adb shell <command> - run remote shell command
41
adb emu <command> - run emulator console command
42
adb logcat [ <filter-spec> ] - View device log
43
adb forward --list - list all forward socket connections.
44
the format is a list of lines with the following format:
45
<serial> " " <local> " " <remote> "\n"
46
adb forward <local> <remote> - forward socket connections
47
forward specs are one of:
48
tcp:<port>
49
localabstract:<unix domain socket name>
50
localreserved:<unix domain socket name>
51
localfilesystem:<unix domain socket name>
52
dev:<character device name>
53
jdwp:<process pid> (remote only)
54
adb forward --no-rebind <local> <remote>
55
- same as 'adb forward <local> <remote>' but fails
56
if <local> is already forwarded
57
adb forward --remove <local> - remove a specific forward socket connection
58
adb forward --remove-all - remove all forward socket connections
59
adb reverse --list - list all reverse socket connections from device
60
adb reverse <remote> <local> - reverse socket connections
61
reverse specs are one of:
62
tcp:<port>
63
localabstract:<unix domain socket name>
64
localreserved:<unix domain socket name>
65
localfilesystem:<unix domain socket name>
66
adb reverse --norebind <remote> <local>
67
- same as 'adb reverse <remote> <local>' but fails
68
if <remote> is already reversed.
69
adb reverse --remove <remote>
70
- remove a specific reversed socket connection
71
adb reverse --remove-all - remove all reversed socket connections from device
72
adb jdwp - list PIDs of processes hosting a JDWP transport
73
adb install [-lrtsdg] <file>
74
- push this package file to the device and install it
75
(-l: forward lock application)
76
(-r: replace existing application)
77
(-t: allow test packages)
78
(-s: install application on sdcard)
79
(-d: allow version code downgrade)
80
(-g: grant all runtime permissions)
81
adb install-multiple [-lrtsdpg] <file...>
82
- push this package file to the device and install it
83
(-l: forward lock application)
84
(-r: replace existing application)
85
(-t: allow test packages)
86
(-s: install application on sdcard)
87
(-d: allow version code downgrade)
88
(-p: partial application install)
89
(-g: grant all runtime permissions)
90
adb uninstall [-k] <package> - remove this app package from the device
91
('-k' means keep the data and cache directories)
92
adb bugreport - return all information from the device
93
that should be included in a bug report.
94
95
adb backup [-f <file>] [-apk|-noapk] [-obb|-noobb] [-shared|-noshared] [-all] [-system|-nosystem] [<packages...>]
96
- write an archive of the device's data to <file>.
97
If no -f option is supplied then the data is written
98
to "backup.ab" in the current directory.
99
(-apk|-noapk enable/disable backup of the .apks themselves
100
in the archive; the default is noapk.)
101
(-obb|-noobb enable/disable backup of any installed apk expansion
102
(aka .obb) files associated with each application; the default
103
is noobb.)
104
(-shared|-noshared enable/disable backup of the device's
105
shared storage / SD card contents; the default is noshared.)
106
(-all means to back up all installed applications)
107
(-system|-nosystem toggles whether -all automatically includes
108
system applications; the default is to include system apps)
109
(<packages...> is the list of applications to be backed up. If
110
the -all or -shared flags are passed, then the package
111
list is optional. Applications explicitly given on the
112
command line will be included even if -nosystem would
113
ordinarily cause them to be omitted.)
114
115
adb restore <file> - restore device contents from the <file> backup archive
116
117
adb disable-verity - disable dm-verity checking on USERDEBUG builds
118
adb enable-verity - re-enable dm-verity checking on USERDEBUG builds
119
adb keygen <file> - generate adb public/private key. The private key is stored in <file>,
120
and the public key is stored in <file>.pub. Any existing files
121
are overwritten.
122
adb help - show this help message
123
adb version - show version num
124
125
scripting:
126
adb wait-for-device - block until device is online
127
adb start-server - ensure that there is a server running
128
adb kill-server - kill the server if it is running
129
adb get-state - prints: offline | bootloader | device
130
adb get-serialno - prints: <serial-number>
131
adb get-devpath - prints: <device-path>
132
adb remount - remounts the /system, /vendor (if present) and /oem (if present) partitions on the device read-write
133
adb reboot [bootloader|recovery]
134
- reboots the device, optionally into the bootloader or recovery program.
135
adb reboot sideload - reboots the device into the sideload mode in recovery program (adb root required).
136
adb reboot sideload-auto-reboot
137
- reboots into the sideload mode, then reboots automatically after the sideload regardless of the result.
138
adb sideload <file> - sideloads the given package
139
adb root - restarts the adbd daemon with root permissions
140
adb unroot - restarts the adbd daemon without root permissions
141
adb usb - restarts the adbd daemon listening on USB
142
adb tcpip <port> - restarts the adbd daemon listening on TCP on the specified port
143
144
networking:
145
adb ppp <tty> [parameters] - Run PPP over USB.
146
Note: you should not automatically start a PPP connection.
147
<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1
148
[parameters] - Eg. defaultroute debug dump local notty usepeerdns
149
150
adb sync notes: adb sync [ <directory> ]
151
<localdir> can be interpreted in several ways:
152
153
- If <directory> is not specified, /system, /vendor (if present), /oem (if present) and /data partitions will be updated.
154
155
- If it is "system", "vendor", "oem" or "data", only the corresponding partition
156
is updated.
157
158
environment variables:
159
ADB_TRACE - Print debug information. A comma separated list of the following values
160
1 or all, adb, sockets, packets, rwx, usb, sync, sysdeps, transport, jdwp
161
ANDROID_SERIAL - The serial number to connect to. -s takes priority over this if given.
162
ANDROID_LOG_TAGS - When used with the logcat option, only these debug tags are printed.
2018-1-1