用途:在 Android 模拟器中验证应用功能流程,用 adb 驱动导航、输入事件、UI 树检查、截图和日志采集,适用于功能回归测试、UI 缺陷复现和带截图与日志的测试取证。
主要能力与用法:先执行 adb devices 列出模拟器并选定 serial;使用 ./gradlew :<module>:install<BuildVariant> --console=plain --quiet 构建安装,任务名不确定时用 ./gradlew tasks --all | rg install 查询。启动前解析 Activity:adb -s <serial> shell cmd package resolve-activity --brief <package>,再用 adb -s <serial> shell am start -n <package>/<activity> 启动。交互包括点击 adb -s <serial> shell input tap <x> <y>、滑动 adb -s <serial> shell input swipe <x1> <y1> <x2> <y2>、文本 adb -s <serial> shell input text "hello"、返回 adb -s <serial> shell input keyevent 4。截图用 adb -s <serial> exec-out screencap -p > /tmp/emu.png。UI 树用 adb -s <serial> exec-out uiautomator dump /dev/tty 获取,坐标必须从 UI 树的 bounds="[x1,y1][x2,y2]" 推算中心点,而非从截图目测;可借助 scripts/ui_pick.py 与 scripts/ui_tree_summarize.py。若目标节点缺失且存在可滚动元素,应先滑动、重新 dump 并再次搜索。
日志:adb -s <serial> logcat -c 清空;通过 adb -s <serial> shell pidof -s <package> 解析 pid 后用 adb -s <serial> logcat --pid <pid> 流式查看;崩溃缓冲用 adb -s <serial> logcat -b crash;保存用 adb -s <serial> logcat -d > /tmp/logcat.txt。
限制:滑动时避免贴边,建议距左/右约 150-200 px 起始以减少误触返回手势;坐标选取仅依据 UI 树。其他平台、收费与性能数据暂未提供。