标签:
Category | Command | Description | Comments |
---|---|---|---|
Target Device |
-d |
将adb command发送给当期唯一使用USB方式连接的设备 |
如果USB连接设备并不唯一,则会返回错误 |
-e |
将adb command发送给当期唯一连接的模拟器设备 | 如果连接的模拟器并不唯一,则会返回错误 | |
-s <serialNumber> |
将adb command发送给指定模拟器/真机设备(通过其serial number进行指定) |
See Directing Commands to a Specific Emulator/Device Instance. | |
General | devices |
显示当前连接的所有模拟器/真机设备 | See Querying for Emulator/Device Instancesfor more information. |
help |
显示所有支持的adb commands列表 |
|
|
version |
显示adb版本信息 |
|
|
Debug | logcat [option] [filter-specs] |
将logcat信息显示到屏幕上 |
|
bugreport |
将 dumpsys , dumpstate ,
and logcat 信息显示到屏幕上,用以显示bug |
|
|
jdwp |
显示可用的JDWP进程列表 |
You can use the 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路径名) |
|
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 |
打印所有模拟器/设备的serialno | See Querying for Emulator/Device Instancesfor more information. |
get-state |
打印当前所有模拟器/设备的状态 | ||
wait-for-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 getprop
Note 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>.apk
would 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 |
检查adb server是否已经启动运行。如果未启动,则将其启动 |
|
kill-server |
终止adb server |
|
|
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. |
1)ADB常用命令:(前面均已提及)
1. 查看设备
adb devices
这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显示
2. 安装软件
adb install <apk文件路径>
这个命令将指定的apk文件安装到设备上
参数“-r”,它是更新安装的意思,
参数 -s ,安装到sdcard.
如: adb install com.sina.weibo.apk
3. 卸载软件
adb uninstall <包名>
如果加 -k 参数,为卸载软件但是保留配置和缓存文件.
如: adb uninstall com.sina.weibo.apk
4. 登录设备shell
adb shell
adbshell <command命令>
这个命令将登录设备的shell.
后面加<command命令>将是直接运行设备命令, 相当于执行远程命令
如: adb shell cat /proc/kmsg
5. 从电脑上发送文件到设备
adb push <本地路径> <远程路径>
用push命令可以把本机电脑上的文件或者文件夹复制到设备(手机)
如: adb push /local/build.prop /system/build.prop
6. 从设备上下载文件到电脑
adb pull <远程路径> <本地路径>
用pull命令可以把设备(手机)上的文件或者文件夹复制到本机电脑
如: adb /system/build.prop /local/
7. 同步更新
adb sync [ <directory> ]
如果不指定目录,将同时更新 /data 和 /system/
如: adb sync /data/
8. 显示帮助信息
adb help
这个命令将显示帮助信息
9. 重新挂载
adb remount
重新挂载系统 分区 用于读写
10. 启动、关闭ADB Server
adb start-server - ensure that there is a server running
adb kill-server - kill the server if it is running
11. 重启设备
adb reboot [bootloader|recovery] - reboots the device, optionally into the bootloader or recovery program
12. 查看Log
[adb] logcat [<option>] ... [<filter-spec>] ..
-b <buffer> 加载一个可使用的日志缓冲区供查看,比如event 和radio . 默认值是main 。具体查看Viewing Alternative Log Buffers.
-c 清楚屏幕上的日志.
-d 输出日志到屏幕上.
-f <filename> 指定输出日志信息的<filename> ,默认是stdout .
-g 输出指定的日志缓冲区,输出后退出.
-n <count> 设置日志的最大数目<count> .,默认值是4,需要和 -r 选项一起使用。
-r <kbytes> 每<kbytes> 时输出日志,默认值为16,需要和-f 选项一起使用.
-s 设置默认的过滤级别为silent.
-v <format> 设置日志输入格式,默认的是brief 格式
where <tag> is a log component tag (or * for all) and priority is:
V Verbose
D Debug
I Info
W Warn
E Error
F Fatal
S Silent (supress all output)
‘*‘ means ‘*:d‘ and <tag> by itself means <tag>:v
13、查看bug报告:
adb bugreport
2)常用adb shell命令:
1. 按键事件
input text <string> input a string to device
input keyevent <event_code> send a Key Event to device
如: adb shell input keyevent 26 (PowerKey)
2. am命令
am start <INTENT> : start an Activity
如 :
am start -n com.android.calculator/com.android.calculator2.Calculator
am broadcast <INTENT>
am startservice <INTENT>
am force-stop <PACKAGE>
am kill <PACKAGE>
am kill-all
am broadcast <INTENT>
"<INTENT> specifications include these flags and arguments:\n" +
" [-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]\n" +
" [-c <CATEGORY> [-c <CATEGORY>] ...]\n" +
" [-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]\n" +
" [--esn <EXTRA_KEY> ...]\n" +
" [--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]\n" +
" [--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]\n" +
" [--el <EXTRA_KEY> <EXTRA_LONG_VALUE> ...]\n" +
" [--eu <EXTRA_KEY> <EXTRA_URI_VALUE> ...]\n" +
" [--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]]\n" +
" [--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]]\n"
" [-n <COMPONENT>] [-f <FLAGS>]\n" +
" [--grant-read-uri-permission] [--grant-write-uri-permission]\n" +
" [--debug-log-resolution] [--exclude-stopped-packages]\n" +
" [--include-stopped-packages]\n" +
" [--activity-brought-to-front] [--activity-clear-top]\n" +
" [--activity-clear-when-task-reset] [--activity-exclude-from-recents]\n" +
" [--activity-launched-from-history] [--activity-multiple-task]\n" +
" [--activity-no-animation] [--activity-no-history]\n" +
" [--activity-no-user-action] [--activity-previous-is-top]\n" +
" [--activity-reorder-to-front] [--activity-reset-task-if-needed]\n" +
" [--activity-single-top] [--activity-clear-task]\n" +
" [--activity-task-on-home]\n" +
" [--receiver-registered-only] [--receiver-replace-pending]\n" +
" [--selector]\n" +
" [<URI> | <PACKAGE> | <COMPONENT>]\n"
更多详细用法请见am 使用帮助.
3. pm 命令
pm list packages
-f: see their associated file
-s: filter to only show system packages
-3 ilter to only show third party packages
pm list packages [-f] [-d] [-e] [-s] [-e] [-u] [FILTER]");
pm list permission-groups
pm list permissions [-g] [-f] [-d] [-u] [GROUP]");
pm list instrumentation [-f] [TARGET-PACKAGE]");
pm list features
pm list libraries
pm path PACKAGE
pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] [-s] [-f] PATH
pm uninstall [-k] PACKAGE
pm clear PACKAGE
pm enable PACKAGE_OR_COMPONENT
pm disable PACKAGE_OR_COMPONENT
pm disable-user PACKAGE_OR_COMPONENT
pm set-install-location [0/auto] [1/internal] [2/external]
pm get-install-location
更多詳细用法,请见pm使用帮助.
4. dumpsys
dumpsys activity
dumpsys activity intents
dumpsys activity broadcasts
dumpsys activity providers
dumpsys activity services
dumpsys activity activities
dumpsys activity processes
dumpsys window
dumpsys window windows
dumpsys window tokens
dumpsys window sessions
dumpsys window policy
dumpsys window input
dumpsys statusbar
dumpsys notification
dumpsys package [<PACKAGE> ]
dumpsys location
dumpsys alarm
dumpsys connectivity
dumpsys wifi
…....等等
5. ime 输入法管理
ime list [-a] [-s]
list command prints all enabled input methods
-s option to see only a single summary line of each.
-a option to see all input method
ime enable ID
ime disable ID
ime set ID
LOCAL_PATH:= $(call my-dir) # adb host tool # ========================================================= include $(CLEAR_VARS) # Default to a virtual (sockets) usb interface USB_SRCS := EXTRA_SRCS := .............. #涉及到的源码文件 LOCAL_SRC_FILES := adb.c console.c transport.c transport_local.c transport_usb.c commandline.c adb_client.c adb_auth_host.c sockets.c services.c file_sync_client.c $(EXTRA_SRCS) $(USB_SRCS) usb_vendors.c LOCAL_C_INCLUDES += external/openssl/include ifneq ($(USE_SYSDEPS_WIN32),) LOCAL_SRC_FILES += sysdeps_win32.c else LOCAL_SRC_FILES += fdevent.c endif #注意这里定义的全局宏 ADB_HOST = 1 LOCAL_CFLAGS += -O2 -g -DADB_HOST=1 -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE #模块名称为adb LOCAL_MODULE := adb LOCAL_MODULE_TAGS := debug
# adbd device daemon # ========================================================= include $(CLEAR_VARS) #使用的源文件,可以看到源代码并未对ADB_HOST与ADB Daemon在文件上严格地界限开来, #两者共同地使用了许多文件,就使得前面定义的全局宏ADB_HOST显得十分重要 LOCAL_SRC_FILES := adb.c fdevent.c transport.c transport_local.c transport_usb.c adb_auth_client.c sockets.c services.c file_sync_service.c jdwp_service.c framebuffer_service.c remount_service.c disable_verity_service.c usb_linux_client.c #这里相区别的定义的全局宏ADB_HOST为0 LOCAL_CFLAGS := -O2 -g -DADB_HOST=0 -Wall -Wno-unused-parameter -Werror LOCAL_CFLAGS += -D_XOPEN_SOURCE -D_GNU_SOURCE ifneq (,$(filter userdebug eng,$(TARGET_BUILD_VARIANT))) LOCAL_CFLAGS += -DALLOW_ADBD_ROOT=1 endif ifneq (,$(filter userdebug,$(TARGET_BUILD_VARIANT))) LOCAL_CFLAGS += -DALLOW_ADBD_DISABLE_VERITY=1 endif #模块名 LOCAL_MODULE := adbd
# path: /system/core/rootdir/init.rc # adbd is controlled via property triggers in init.<platform>.usb.rc service adbd /sbin/adbd --root_seclabel=u:r:su:s0 class core socket adbd stream 660 system system disabled seclabel u:r:adbd:s0 # adbd on at boot in emulator on property:ro.kernel.qemu=1 start adbd
/** @path: \system\core\adb\adb.c **/ int main(int argc, char **argv) { /** 看到前面定义的ADB_HOST宏即是用来区分ADB Client/Server与ADB Daemon, * 系统会对其进行分别编译 **/ #if ADB_HOST adb_sysdeps_init(); adb_trace_init(); D("Handling commandline()\n"); return adb_commandline(argc - 1, argv + 1); #else /** 如果adbd运行在模拟器中,它将允许adb在模拟器中追踪via adb-debug qemud service*/ adb_qemu_trace_init(); while(1) { int c; int option_index = 0; static structoption opts[] = { {"root_seclabel", required_argument, 0, 's' }, {"device_banner", required_argument, 0, 'b' } }; c = getopt_long(argc, argv, "", opts, &option_index); if (c == -1) break; switch (c) { case's': root_seclabel = optarg; break; case'b': adb_device_banner = optarg; break; default: break; } } start_device_log(); D("Handling main()\n"); return adb_main(0, DEFAULT_ADB_PORT); #endif }
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/woliuyunyicai/article/details/47835671