ADB Tool 调试场景 & 常用命令

2022-08-22· 50min

#ADB(Android Debug Bridge)

#连接手机 <-> 电脑

  1. USB 线连接手机 & 电脑
  2. 在手机上开启 USB 调试权限:
    • 打开 设置 -> 点击 系统 -> 多次点击 关于手机 或者 手机版本号
    • 返回 系统 -> 打开 开发者选项 -> 开启 USB调试
  3. 查看手机 & 电脑,若有弹窗权限 -> 允许
  • PS:
    • 可多次重复插拔数据线测试
    • 常用于 webview 调试

#测试命令

$ adb devices
  List of devices attached
  7XV8N15315113152  device

#安装APK

# 将本地 xxx.apk 安装到手机
$ adb install /YourPath/xxx.apk
  Performing Streamed Install
  Success

#文件传输

# 将本地 xxx.txt 文件 -> 手机 /sdcard/Download 目录下
$ adb push /YourPath/xxx.txt /sdcard/Download/
  /YourPath/xxx.txt: 1 file..., 0 skipped. 0.0 MB/s (53 bytes in 0.008s)

# 手机 /sdcard/Download 目录下 yyy.txt 文件 -> 本地 /YourPath/xxx
$ adb pull /sdcard/Download/yyy.txt /YourPath/xxx
  /sdcard/Download/yyy.txt: 1 file pulled, 0 skipped. 0.0 MB/s (84 bytes in 0.010s)

#复制粘贴

  • 因系统差异 & 权限复杂,故采取以下曲线救机的方式
# 1. 先在手机上的输入框聚焦
# 2. 再将文字 hello-input-tttt 输入到手机的输入框
$ adb shell input text hello-input-tttt