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

托管设备运行基准配置文件测试时APK安装失败求助

基准配置文件测试APK安装失败排查求助

在托管设备上运行基准配置文件测试时遭遇PluginException,提示APK安装失败。

执行的命令

./gradlew :macro-benchmark:pixel2Api31ReleaseAndroidTest -P android.testInstrumentationRunnerArguments.class=com.benchmark.BaselineProfileGenerator -DBUILD_VARIANT=release

报错信息

> Task :macro-benchmark:pixel2Api31ReleaseAndroidTest FAILED
Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin.
Failed to install APK: /Users/surajvaishnav/AndroidStudioProjects/MyProject/app/build/outputs/apk/release/app-release-d70a.apk, with option -r,-t
com.google.testing.platform.api.plugin.PluginException: Failed to install APK: /Users/surajvaishnav/AndroidStudioProjects/MyProject/app/build/outputs/apk/release/app-release-d70a.apk, with option -r,-t
        at com.google.testing.platform.plugin.android.AndroidDevicePlugin.beforeAll(AndroidDevicePlugin.kt:109)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1$2$1.invoke(PluginLifecycle.kt:93)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1$2$1.invoke(PluginLifecycle.kt:92)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:213)
        at com.google.testing.platform.plugin.PluginLifecycleKt$invokeOrThrow$1.invoke(PluginLifecycle.kt:212)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:212)
        at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow$default(PluginLifecycle.kt:205)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:92)
        at com.google.testing.platform.plugin.PluginLifecycle$onBeforeAll$1.invoke(PluginLifecycle.kt:88)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:105)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent$default(Telemetry.kt:98)
        at com.google.testing.platform.plugin.PluginLifecycle.onBeforeAll(PluginLifecycle.kt:88)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor$execute$4.invoke(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.executor.SingleDeviceExecutor.runUnlessCancelled(SingleDeviceExecutor.kt:105)
        at com.google.testing.platform.executor.SingleDeviceExecutor.execute(SingleDeviceExecutor.kt:86)
        at com.google.testing.platform.RunnerImpl.run(RunnerImpl.kt:108)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:80)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy$run$4.invoke(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.core.telemetry.common.noop.NoopDiagnosticsScope.recordEvent(NoopDiagnosticsScope.kt:35)
        at com.google.testing.platform.core.telemetry.TelemetryKt.recordEvent(Telemetry.kt:66)
        at com.google.testing.platform.server.strategy.NonInteractiveServerStrategy.run(NonInteractiveServerStrategy.kt:79)
        at com.google.testing.platform.main.MainKt$main$4.invokeSuspend(Main.kt:67)
        at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
        at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
        at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
        at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:85)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
        at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
        at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
        at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
        at com.google.testing.platform.main.MainKt.main(Main.kt:66)
        at com.google.testing.platform.main.MainKt.main$default(Main.kt:34)
        at com.google.testing.platform.main.MainKt.main(Main.kt)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.google.testing.platform.launcher.Launcher.main(Launcher.java:149)

测试文件代码

@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator {

    @get:Rule
    val rule = BaselineProfileRule()

    @Test
    fun generate() = rule.collectBaselineProfile("com.example.myapp"){
        startActivityAndWait()
    }
}

排查建议

  • 手动执行APK安装命令,获取具体错误:使用adb install -r -t /Users/surajvaishnav/AndroidStudioProjects/MyProject/app/build/outputs/apk/release/app-release-d70a.apk,查看是否有签名不匹配、空间不足、API版本不兼容等明确提示
  • 验证APK有效性:通过aapt dump badging /path/to/apk检查APK的包名、目标SDK版本等信息,确认与测试配置一致
  • 核对测试代码包名:collectBaselineProfile传入的com.example.myapp必须与APK实际包名完全一致
  • 检查托管设备状态:确认设备未锁定、已开启调试模式,且连接状态正常
  • 验证构建配置:确保macro-benchmark模块已正确依赖主应用的release变体,且签名配置与主应用保持一致
  • 查看详细构建日志:执行命令时添加--info参数,获取安装过程的完整日志,定位具体失败环节

内容的提问来源于stack exchange,提问作者Suraj Vaishnav

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 16:50:24