当前位置:   article > 正文

adb(安卓调试桥)命令-新手入门自学笔记_adb获取usb调试权限

adb获取usb调试权限

ADB,即 Android Debug Bridge,它是 Android 开发/测试人员不可替代的强大工具,也是 Android 设备玩家的好玩具。安卓调试桥 (Android Debug Bridge, adb),是一种可以用来操作手机设备或模拟器的命令行工具。

一、打开手机端USB调试授权

首先我们需要进入开发者模式,以华为mate30手机为例,打开“设置”,拉到最下方,点击“关于手机”,连续点击五次“版本号”,手机会弹出提示您已进入开发者模式(图1)。然后返回上一层“设置”界面,点击“系统和更新”,再找到“开发人员选项”点击进入(图2),向下滑动找到“USB调试”选项并开启,再点击“确定”就OK了(图3)。

           

当手机通过USB线连接到电脑时,手机通知栏会有“已连接USB调试”的提示(上图,图4)(不过并不确定是不是所有手机都会有这个提示)。如果想查看手机是否已经成功能进行USB调试,还有其他方法,即在电脑上cmd如下命令:

adb devices

此时,窗口中会列出设备的序列号,此时就可以使用adb命令对手机进行调试了。

二、常用adb命令

1、打开adb帮助

adb help

然后窗口中会展示超长一段adb的命令用法介绍,如下所示(不过对于新手来说,看这些命令不如查CSDN来的快):

  1. global options:
  2. -a listen on all network interfaces, not just localhost
  3. -d use USB device (error if multiple devices connected)
  4. -e use TCP/IP device (error if multiple TCP/IP devices available)
  5. -s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
  6. -t ID use device with given transport id
  7. -H name of adb server host [default=localhost]
  8. -P port of adb server [default=5037]
  9. -L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]
  10. general commands:
  11. devices [-l] list connected devices (-l for long output)
  12. help show this help message
  13. version show version num
  14. networking:
  15. connect HOST[:PORT] connect to a device via TCP/IP [default port=5555]
  16. disconnect [HOST[:PORT]]
  17. disconnect from given TCP/IP device [default port=5555], or all
  18. pair HOST[:PORT] pair with a device for secure TCP/IP communication
  19. forward --list list all forward socket connections
  20. forward [--no-rebind] LOCAL REMOTE
  21. forward socket connection using:
  22. tcp:<port> (<local> may be "tcp:0" to pick any open port)
  23. localabstract:<unix domain socket name>
  24. localreserved:<unix domain socket name>
  25. localfilesystem:<unix domain socket name>
  26. dev:<character device name>
  27. jdwp:<process pid> (remote only)
  28. acceptfd:<fd> (listen only)
  29. forward --remove LOCAL remove specific forward socket connection
  30. forward --remove-all remove all forward socket connections
  31. ppp TTY [PARAMETER...] run PPP over USB
  32. reverse --list list all reverse socket connections from device
  33. reverse [--no-rebind] REMOTE LOCAL
  34. reverse socket connection using:
  35. tcp:<port> (<remote> may be "tcp:0" to pick any open port)
  36. localabstract:<unix domain socket name>
  37. localreserved:<unix domain socket name>
  38. localfilesystem:<unix domain socket name>
  39. reverse --remove REMOTE remove specific reverse socket connection
  40. reverse --remove-all remove all reverse socket connections from device
  41. file transfer:
  42. push [--sync] [-zZ] LOCAL... REMOTE
  43. copy local files/directories to device
  44. --sync: only push files that are newer on the host than the device
  45. -z: enable compression
  46. -Z: disable compression
  47. pull [-azZ] REMOTE... LOCAL
  48. copy files/dirs from device
  49. -a: preserve file timestamp and mode
  50. -z: enable compression
  51. -Z: disable compression
  52. sync [-lzZ] [all|data|odm|oem|product|system|system_ext|vendor]
  53. sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)
  54. -l: list files that would be copied, but don't copy them
  55. -z: enable compression
  56. -Z: disable compression
  57. shell:
  58. shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]
  59. run remote shell command (interactive shell if no command given)
  60. -e: choose escape character, or "none"; default '~'
  61. -n: don't read from stdin
  62. -T: disable pty allocation
  63. -t: allocate a pty if on a tty (-tt: force pty allocation)
  64. -x: disable remote exit codes and stdout/stderr separation
  65. emu COMMAND run emulator console command
  66. app installation (see also `adb shell cmd package help`):
  67. install [-lrtsdg] [--instant] PACKAGE
  68. push a single package to the device and install it
  69. install-multiple [-lrtsdpg] [--instant] PACKAGE...
  70. push multiple APKs to the device for a single package and install them
  71. install-multi-package [-lrtsdpg] [--instant] PACKAGE...
  72. push one or more packages to the device and install them atomically
  73. -r: replace existing application
  74. -t: allow test packages
  75. -d: allow version code downgrade (debuggable packages only)
  76. -p: partial application install (install-multiple only)
  77. -g: grant all runtime permissions
  78. --abi ABI: override platform's default ABI
  79. --instant: cause the app to be installed as an ephemeral install app
  80. --no-streaming: always push APK to device and invoke Package Manager as separate steps
  81. --streaming: force streaming APK directly into Package Manager
  82. --fastdeploy: use fast deploy
  83. --no-fastdeploy: prevent use of fast deploy
  84. --force-agent: force update of deployment agent when using fast deploy
  85. --date-check-agent: update deployment agent when local version is newer and using fast deploy
  86. --version-check-agent: update deployment agent when local version has different version code and using fast deploy
  87. (See also `adb shell pm help` for more options.)
  88. uninstall [-k] PACKAGE
  89. remove this app package from the device
  90. '-k': keep the data and cache directories
  91. debugging:
  92. bugreport [PATH]
  93. write bugreport to given PATH [default=bugreport.zip];
  94. if PATH is a directory, the bug report is saved in that directory.
  95. devices that don't support zipped bug reports output to stdout.
  96. jdwp list pids of processes hosting a JDWP transport
  97. logcat show device log (logcat --help for more)
  98. security:
  99. disable-verity disable dm-verity checking on userdebug builds
  100. enable-verity re-enable dm-verity checking on userdebug builds
  101. keygen FILE
  102. generate adb public/private key; private key stored in FILE,
  103. scripting:
  104. wait-for[-TRANSPORT]-STATE...
  105. wait for device to be in a given state
  106. STATE: device, recovery, rescue, sideload, bootloader, or disconnect
  107. TRANSPORT: usb, local, or any [default=any]
  108. get-state print offline | bootloader | device
  109. get-serialno print <serial-number>
  110. get-devpath print <device-path>
  111. remount [-R]
  112. remount partitions read-write. if a reboot is required, -R will
  113. will automatically reboot the device.
  114. reboot [bootloader|recovery|sideload|sideload-auto-reboot]
  115. reboot the device; defaults to booting system image but
  116. supports bootloader and recovery too. sideload reboots
  117. into recovery and automatically starts sideload mode,
  118. sideload-auto-reboot is the same but reboots after sideloading.
  119. sideload OTAPACKAGE sideload the given full OTA package
  120. root restart adbd with root permissions
  121. unroot restart adbd without root permissions
  122. usb restart adbd listening on USB
  123. tcpip PORT restart adbd listening on TCP on PORT
  124. internal debugging:
  125. start-server ensure that there is a server running
  126. kill-server kill the server if it is running
  127. reconnect kick connection from host side to force reconnect
  128. reconnect device kick connection from device side to force reconnect
  129. reconnect offline reset offline/unauthorized devices to force reconnect
  130. environment variables:
  131. $ADB_TRACE
  132. comma-separated list of debug info to log:
  133. all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
  134. $ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
  135. $ANDROID_SERIAL serial number to connect to (see -s)
  136. $ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
  137. $ADB_LOCAL_TRANSPORT_MAX_PORT max emulator scan port (default 5585, 16 emus)

2、查看已连接到电脑的设备

adb devices

 3、重启设备

adb reboot

4、查看和储存日志

adb logcat

 手机内的日志分为四个缓冲区,分别为main,system,radio和event。main区域中为手机应用软件日志,system中为系统组件日志,radio中为通信日志,event中为手机按键输入等事件日志。我们通常使用如下命令使屏幕实时显示指定缓冲区的日志:

若想停止获取日志,按"Ctrl+C"即可终止。

  1. adb logcat -b main
  2. adb logcat -b system
  3. adb logcat -b radio
  4. adb logcat -b event

若想要将日志保存至电脑指定位置,可使用以下命令(此时,窗口不会实时显示日志内容):

adb logcat -b main > <path>

<path>为储存日志的地址,示例如下:

adb logcat -b radio > D:\log.txt

当想要停止获取日志,按"Ctrl+C"即可,此时打开日志存储路径便可查看获取到的日志内容。

5、安装程序至手机

adb install <apk>

<apk>为手机程序安装包所在地址,可直接将安装包用鼠标拖至窗口中,安装包地址便会自动呈现在窗口上,示例如下:

adb install D:\baidu.apk

6、卸载手机中的程序

adb uninstall <package>
adb uninstall com.huawei.health

这个命令与安装程序有很大的区别,<package>为程序的包名,包名无法直接在手机上查到,当然可以通过安装一些插件或小程序查到,不过显然通过adb命令查包名会更加容易,方法如7中所示。

7、查手机程序包名

adb shell am monitor

这个命令可以实时查看打开的程序的包名,窗口会实时显示你在手机中打开的程序的包名,想卸载哪个程序先运行一下就知道他的包名了。

adb shell pm list packages

这个命令可以查看手机上所有已安装程序的包名,不过缺点就是一次性显示所有的包名会有点混乱......你不一定能找得到你想要找的程序包名

8、电脑传文件到手机中

adb push <laptop_path> <phone_path>

<laptop_path>是电脑端要传的文件路径

<phone_path>是移动端存储文件的路径

9、手机传文件到电脑中

adb push <phone_path> <laptop_path>

<laptop_path>是电脑端要传的文件路径

<phone_path>是移动端存储文件的路径

作为一个入门级新手来说,这些adb命令够玩好久了。那就开始吧!!

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号