用adb命令打开usb调试 (华为手机adb调试是什么意思)

版本信息

Android Debug Bridge version 1.0.41

Version 29.0.4-5871666

Installed as c:\tmp\fastboot\adb*ex.e**

一、global options : (全局选项)

  • -a listen on all network interfaces, not just localhost
  • -d use USB device (error if multiple devices connected)
  • -e use TCP/IP device (error if multiple TCP/IP devices available)
  • -s SERIAL use device with given serial (overrides $ANDROID_SERIAL)
  • -t ID use device with given transport id
  • -H name of adb server host [default=localhost] 有多台设备时指定连哪一台
  • -P port of adb server [default=5037] 指定连接端口
  • -L SOCKET listen on given socket for adb server [default=tcp:localhost:5037]

二、general commands :(常用命令)

  • devices [-l] list connected devices (-l for long output)

查看连接的设备,显示出设备号和状态。当设备处于正常连接、bootloader、recovery、sideload时,状态对应为:device/fastboot/recovery/sideload。unauthorized是设备端未授权。

c:\tmp\fastboot>adb devices
List of devices attached
ZHP7UCQCFUKNEMBQ        device
  • help show this help message
  • version show version num 显示当前adb的版本
c:\tmp\fastboot>adb version
Android Debug Bridge version 1.0.41
Version 29.0.4-5871666
Installed as c:\tmp\fastboot\adb*ex.e**

三、networking : (网络功能)

connect HOST[:PORT] connect to a device via TCP/IP (设备与电脑同一局域网)

通过网络连接设备,默认端口是:5555

c:\tmp\fastboot>adb connect 192.168.0.4
cannot connect to 192.168.0.4:5555: 由于目标计算机积极拒绝,无法连接。 (10061)

disconnect [[HOST]:PORT] disconnect from given TCP/IP device, or all

forward --list list all forward socket connections

forward [--no-rebind] LOCAL REMOTE

forward socket connection using:

tcp:<port> (<local> may be "tcp:0" to pick any open 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)

forward --remove LOCAL remove specific forward socket connection

forward --remove-all remove all forward socket connections

ppp TTY [PARAMETER...] run PPP over USB

reverse --list list all reverse socket connections from device

reverse [--no-rebind] REMOTE LOCAL

reverse socket connection using:

tcp:<port> (<remote> may be "tcp:0" to pick any open port)

localabstract:<unix domain socket name>

localreserved:<unix domain socket name>

localfilesystem:<unix domain socket name>

reverse --remove REMOTE remove specific reverse socket connection

reverse --remove-all remove all reverse socket connections from device

四、file transfer : (文件传输功能)

push [--sync] LOCAL... REMOTE 将电脑上的文件传到设备上

copy local files/directories to device

--sync: only push files that are newer on the host than the device

c:\tmp\fastboot>adb push c:/tmp/adbd-Insecure-v2.00.apk  /sdcard/
c:/tmp/adbd-Insecure-v2.00.apk: 1 file ...shed. 7.3 MB/s (752250 bytes in 0.099s)

pull [-a] REMOTE... LOCAL 将设备上的文件*载下**到电脑上

copy files/dirs from device

-a: preserve file timestamp and mode

adb pull /sdcard/adbd-Insecure-v2.00.apk  c:/tmp/

sync [all|data|odm|oem|product|system|system_ext|vendor]

sync a local build from $ANDROID_PRODUCT_OUT to the device (default all)

-l: list files that would be copied, but don't copy them

五、shell : (shell功能)

shell [-e ESCAPE] [-n] [-Tt] [-x] [COMMAND...]

run remote shell command (interactive shell if no command given)

  • -e: choose escape character, or "none"; default '~'
  • -n: don't read from stdin
  • -T: disable PTY allocation
  • -t: force PTY allocation
  • -x: disable remote exit codes and stdout/stderr separation

进入shell命令模式或直接执行sh命令:

c:\tmp\fastboot>adb shell
shell@bbk82_wet_jb5:/ $

c:\tmp\fastboot>adb shell ls -l /system/
drwxrwxrwx root     root              2022-02-19 20:07 app
drwxr-xr-x root     shell             2022-02-24 09:53 bin
-rw-r--r-- root     root         4289 2015-03-10 11:55 build.prop
drwxr-xr-x root     root              2008-08-01 20:00 com.bbk.arcsoft
drwxr-xr-x root     root              2008-08-01 20:00 etc
drwxr-xr-x root     root              2008-08-01 20:00 fonts
...

emu COMMAND run emulator console command

六、app installation (see also `adb shell cmd package help`) : (应用安装)

install [-lrtsdg] [--instant] PACKAGE 安装本地(电脑端)的APP到设备上

push a single package to the device and install it

c:\tmp\fastboot>adb install c:/tmp/adbd-Insecure-v2.00.apk
Performing Push Install
c:/tmp/adbd-Insecure-v2.00.apk: 1 file ...shed. 7.5 MB/s (752250 bytes in 0.096s)
        pkg: /data/local/tmp/adbd-Insecure-v2.00.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]

install-multiple [-lrtsdpg] [--instant] PACKAGE...

push multiple APKs to the device for a single package and install them

install-multi-package [-lrtsdpg] [--instant] PACKAGE...

push one or more packages to the device and install them atomically

  • -r: replace existing application
  • -t: allow test packages
  • -d: allow version code downgrade (debuggable packages only)
  • -p: partial application install (install-multiple only)
  • -g: grant all runtime permissions
  • --abi ABI: override platform's default ABI
  • --instant: cause the app to be installed as an ephemeral install app
  • --no-streaming: always push APK to device and invoke Package Manager as separate steps
  • --streaming: force streaming APK directly into Package Manager
  • --fastdeploy: use fast deploy
  • --no-fastdeploy: prevent use of fast deploy
  • --force-agent: force update of deployment agent when using fast deploy
  • --date-check-agent: update deployment agent when local version is newer and using fast deploy
  • --version-check-agent: update deployment agent when local version has different version code and using fast deploy

(See also `adb shell pm help` for more options.)

uninstall [-k] PACKAGE

remove this app package from the device

'-k': keep the data and cache directories

七、debugging : (调试功能)

bugreport [PATH]

write bugreport to given PATH [default=bugreport.zip];

if PATH is a directory, the bug report is saved in that directory.

devices that don't support zipped bug reports output to stdout.

jdwp list pids of processes hosting a JDWP transport

logcat show device log (logcat --help for more)

八、security :

  • disable-verity disable dm-verity checking on userdebug builds
  • enable-verity re-enable dm-verity checking on userdebug builds
  • keygen FILE generate adb public/private key; private key stored in FILE

九、scripting :

wait-for[-TRANSPORT]-STATE

wait for device to be in the given state

  • STATE: device, recovery, rescue, sideload, bootloader, or disconnect
  • TRANSPORT: usb, local, or any [default=any]

get-state print offline | bootloader | device 取得设备的状态

c:\tmp\fastboot>adb get-state
device

get-serialno print <serial-number> 取得设备号

c:\tmp\fastboot>adb get-serialno
ZHP7UCQCFUKNEMBQ

get-devpath print <device-path>

remount [-R] 将分区挂载为可读写

remount partitions read-write. if a reboot is required, -R will automatically reboot the device.

reboot [bootloader|recovery|sideload|sideload-auto-reboot] 重启到各种模式

reboot the device; defaults to booting system image but supports bootloader and recovery too. sideload reboots into recovery and automatically starts sideload mode, sideload-auto-reboot is the same but reboots after sideloading.

默认是正常启动

adb reboot											重启设备
adb reboot bootloader   启动到fastboot模式
adb reboot recovery       启动到recovery模式
adb reboot sideload       启动到sideload传输模式

sideload OTAPACKAGE sideload the given full OTA package

root restart adbd with root permissions 以root的权限来运行adb

adb root

unroot restart adbd without root permissions

usb restart adbd listening on USB

tcpip PORT restart adbd listening on TCP on PORT 修改设备端的网络侦听端口

adb tcpip 9999  (默认是5555)

十、internal debugging :

  • start-server ensure that there is a server running 重启adb服务
  • kill-server kill the server if it is running 关闭adb服务
  • reconnect kick connection from host side to force reconnect
  • reconnect device kick connection from device side to force reconnect
  • reconnect offline reset offline/unauthorized devices to force reconnect
c:\tmp\fastboot>adb kill-server

c:\tmp\fastboot>adb start-server
* daemon not running; starting now at tcp:5037
* daemon started successfully

十一、environment variables :

  • $ADB_TRACE comma-separated list of debug info to log: all,adb,sockets,packets,rwx,usb,sync,sysdeps,transport,jdwp
  • $ADB_VENDOR_KEYS colon-separated list of keys (files or directories)
  • $ANDROID_SERIAL serial number to connect to (see -s)
  • $ANDROID_LOG_TAGS tags to be used by logcat (see logcat --help)
  • $ADB_LOCAL_TRANSPORT_MAX_PORT max emulator scan port (default 5585, 16 emus)

特殊功能 :备份和恢复

  • adb backup
  • adb restore

详细用法在另一篇文章中说明。