用途:把单个 adb 操作组织成可靠的 CI 流水线,处理退出码传播、重试、超时、多设备并行、端口转发、幂等初始化、失败抓取与 Test Orchestrator 接入。
主要能力:说明 adb push/pull/install 的退出码行为;平台工具 24+ 且设备 API 24+ 时 adb shell 会传播设备端退出码;am instrument 始终退出 0,须解析 INSTRUMENTATION_STATUS_CODE(-1 错误、-2 失败,-3/-4 为跳过);adb forward(LOCAL REMOTE)与 adb reverse(REMOTE LOCAL)参数顺序相反;用 timeout 包裹而非 adb -t;对 device not found、closed 等瞬时错误重试并重启 adb;用 xargs -P 做多设备扇出与 numShards/shardIndex 分片;trap 清理动画设置、端口转发与包数据;失败时抓取截屏与 logcat。
用法要点:CI 中以 INSTRUMENTATION_STATUS_CODE 判成败而非 $?;端口转发用 trap 移除;Orchestrator 依赖用 androidTestUtil 而非 androidTestImplementation,直接调用需 --force-queryable。
限制:需先掌握各单项 adb 原语;CI 平台与云配置属 FTL 文档范围;Orchestrator 每测试独立进程会明显增加耗时。