Android adb 常用命令整理

Android2026-08-18

做 Android 自动化测试,adb 是每天都要用的工具,把最常用的命令整理一份。

截屏与录屏

adb exec-out screencap -p > screen.png
adb shell screenrecord /sdcard/demo.mp4   # Ctrl+C 结束
adb pull /sdcard/demo.mp4

注入输入

adb shell input tap 500 800          # 点击坐标
adb shell input swipe 300 900 300 300 300  # 滑动,时长300ms
adb shell input text "hello"
adb shell input keyevent 26           # 电源键

查前台 Activity

adb shell dumpsys activity top | grep ACTIVITY

写自动化脚本前先确认当前界面,比截图更快。

日志

adb logcat -s MyApp:V *:S      # 只看指定tag
adb logcat --pid=$(adb shell pidof -s com.example.app)

实用小技巧

  • adb shell wm size 查分辨率,适配多机型必用
  • adb shell settings get global airplane_mode_on 读系统设置
  • adb shell am start -n com.example/.MainActivity 直接拉起页面
  • 多设备时 adb -s 序列号 指定目标

← 返回首页