Skip to content

adb ​

​

1. 设备连接与管理 ​

查看已连接设备 ​

bash
adb devices

重启设备 ​

bash
adb reboot

进入 Fastboot 模式 ​

bash
adb reboot bootloader

进入 Recovery 模式 ​

bash
adb reboot recovery

查看设备信息 ​

bash
adb shell getprop ro.product.model  # 设备型号
adb shell getprop ro.build.version.release  # Android 版本
adb shell wm size  # 屏幕分辨率
adb shell dumpsys battery  # 电池状态

2. 文件管理 ​

从电脑复制文件到设备 ​

bash
adb push local_file /sdcard/remote_path/

从设备复制文件到电脑 ​

bash
adb pull /sdcard/remote_file local_path/

列出设备文件 ​

bash
adb shell ls /sdcard/

删除设备文件 ​

bash
adb shell rm /sdcard/file_to_delete

进入设备 Shell ​

bash
adb shell

(退出 Shell 使用 exit 或 Ctrl + D)


3. 应用管理 ​

安装 APK ​

bash
adb install app.apk
adb install -r app.apk  # 覆盖安装
adb install -t app.apk  # 允许测试包

卸载应用 ​

bash
adb uninstall com.example.package

列出所有已安装应用 ​

bash
adb shell pm list packages
adb shell pm list packages -f  # 带 APK 路径
adb shell pm list packages -3  # 仅第三方应用

清除应用数据 ​

bash
adb shell pm clear com.example.package

启动应用 ​

bash
adb shell am start -n com.example.package/.MainActivity

强制停止应用 ​

bash
adb shell am force-stop com.example.package

4. 日志与调试 ​

查看实时日志 ​

bash
adb logcat
adb logcat -s TAG  # 过滤特定 Tag
adb logcat *:E  # 仅显示错误日志

清除日志 ​

bash
adb logcat -c

查看 CPU 使用情况 ​

bash
adb shell top

查看内存占用 ​

bash
adb shell dumpsys meminfo
adb shell dumpsys meminfo com.example.package  # 查看特定应用

查看当前 Activity ​

bash
adb shell dumpsys window | grep mCurrentFocus

5. 屏幕操作 ​

截图 ​

bash
adb exec-out screencap -p > screenshot.png
adb shell screencap -p /sdcard/screen.png  # 保存到设备
adb pull /sdcard/screen.png  # 拉取到电脑

录屏 ​

bash
adb shell screenrecord /sdcard/video.mp4
adb pull /sdcard/video.mp4  # 拉取到电脑

(默认 3 分钟,Ctrl + C 停止)

模拟按键 ​

bash
adb shell input keyevent KEYCODE_HOME  # 返回桌面
adb shell input keyevent KEYCODE_BACK  # 返回键
adb shell input keyevent KEYCODE_POWER  # 电源键

(更多 Keycode 见 Android 官方文档)

模拟触摸/滑动 ​

bash
adb shell input tap 500 1000  # 点击 (x=500, y=1000)
adb shell input swipe 300 1000 300 500  # 从 (300,1000) 滑动到 (300,500)

6. 网络调试 ​

查看 IP 地址 ​

bash
adb shell ifconfig
adb shell ip addr show wlan0

查看网络连接 ​

bash
adb shell netstat
adb shell ping google.com

端口转发 ​

bash
adb forward tcp:8080 tcp:8080  # 电脑 8080 映射到设备 8080

7. 高级调试 ​

查看系统属性 ​

bash
adb shell getprop

修改系统设置 ​

bash
adb shell settings put global airplane_mode_on 1  # 开启飞行模式
adb shell settings put system screen_brightness 50  # 亮度 50%

重启 ADB 服务 ​

bash
adb kill-server
adb start-server

无线调试(无需 USB) ​

bash
adb tcpip 5555  # 设置设备监听 5555 端口
adb connect 192.168.1.100:5555  # 连接设备 IP

8. 常见问题 ​

ADB 设备未授权? ​

  1. 检查 USB 调试是否开启(开发者选项 > USB 调试)。
  2. 重新插拔 USB 线,确认授权弹窗。

ADB 命令无响应? ​

bash
adb kill-server && adb start-server

如何查看所有 ADB 命令? ​

bash
adb --help