You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调试时Android Instrumentation Test Runner被强制停止的排查求助

Android自动化测试Debug模式单步调试被ActivityManager强制停止的解决思路

我能够正常运行所有自动化测试,但无法在Debug模式下进行单步调试,测试进程会被ActivityManager强制停止,日志如下:

2023-01-23 09:44:25.000 24226-24266 TestRunner              com.datmedia.mytests.test            I  run started: 1 tests
2023-01-23 09:44:25.022 24226-24266 TestRunner              com.datmedia.mytests.test            I  started: setProperty(com.datmedia.mytests.TestMyKotlinClass)
2023-01-23 09:44:25.102   425-17752 ActivityManager         system_process                       I  Force stopping com.datmedia.mytests.test appid=10142 user=0: from pid 24270
2023-01-23 09:44:25.103   425-17752 ActivityManager         system_process                       I  Killing 24226:com.datmedia.mytests.test/u0a142 (adj 0): stop com.datmedia.mytests.test due to from pid 24270
2023-01-23 09:44:25.106   425-17752 ActivityManager         system_process                       W  Crash of app com.datmedia.mytests.test running instrumentation ComponentInfo{com.datmedia.mytests.test/androidx.test.runner.AndroidJUnitRunner}
2023-01-23 09:44:25.107   425-17752 ActivityManager         system_process                       I  Force stopping com.datmedia.mytests.test appid=10142 user=0: finished inst

以下是排查和解决的思路:

  • 重启ADB服务:调试端口冲突可能导致进程连接异常,执行adb kill-server后再执行adb start-server,重新启动调试。
  • 关闭Instant Run/Apply Changes功能:该功能可能与测试调试存在兼容性问题,路径:File > Settings > Build, Execution, Deployment > Instant Run,取消勾选所有相关选项。
  • 确认调试权限配置:确保测试包的AndroidManifest.xml中添加调试权限:
    <uses-permission android:name="android.permission.SET_DEBUG_APP" />
    
    同时在build.gradle的debug构建类型中设置:
    buildTypes {
        debug {
            debuggable true
        }
    }
    
  • 排查测试代码逻辑:Debug模式下断点暂停会延长进程响应时间,可能触发系统进程清理机制。检查测试代码是否存在死锁、未处理的异常,或者断点位置是否在会触发系统检测的关键逻辑处。
  • 清理测试进程缓存:在设备的应用设置中找到com.datmedia.mytests.test,清除缓存和数据后重新调试。
  • 检查依赖版本兼容性:确保Android Studio、Gradle插件、androidx.test.runner.AndroidJUnitRunner等测试依赖的版本匹配,尝试同步并更新到稳定版本。
  • 定位触发强制停止的进程:日志显示是pid 24270触发的操作,执行adb shell ps | grep 24270查看该进程详情,判断是否是冲突进程或异常系统服务导致。

内容的提问来源于stack exchange,提问作者Andrew Shepherd

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.04 02:05:18