Android 11设备运行BaselineProfileGenerator遇TikTok tracing及执行错误
在Android 11设备上运行BaselineProfileGenerator的报错问题
我在两台Android 11设备(Pixel 2 XL和Pixel 5)上运行BaselineProfileGenerator时出现错误,使用的macrobenchmark库版本为1.2.0-alpha09。
执行Gradle测试命令时的报错
执行命令:
./gradlew :libraries:macrobenchmark:connectedGoogleBenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.class=com.me.macrobenchmark.baselineprofile.BaselineProfileGenerator
抛出异常:
com.google.testing.platform.api.plugin.PluginException: Exception thrown during onBeforeAll invocation of plugin com.google.testing.platform.plugin.android.AndroidDevicePlugin. at com.google.testing.platform.plugin.PluginLifecycleKt.invokeOrThrow(PluginLifecycle.kt:216) ... Caused by: com.google.testing.platform.core.error.UtpException: ErrorName: UNKNOWN NameSpace: DdmlibAndroidDeviceController ErrorCode: 1
执行adb instrument命令时的报错
执行命令:
adb shell am instrument -w -e class com.me.macrobenchmark.baselineprofile.BaselineProfileGenerator#startup com.me.macrobenchmark/androidx.test.runner.AndroidJUnitRunner
抛出重复跟踪错误:
02-15 12:56:04.081 E/TraceManager( 3247): Duplicate trace 02-15 12:56:04.081 E/TraceManager( 3247): com.google.apps.tiktok.tracing.w: Starting new trace A11yEventListener_onChange when already associated with a trace: . For more help, see http://go/tiktok-tracing#fixing-duplicate-trace-issues ...
解决建议
针对Gradle命令的PluginException
- 升级macrobenchmark库:1.2.0-alpha09属于早期预览版,存在UTP设备控制相关的已知bug,建议升级到1.2.x稳定版(如1.2.3及以上),新版本修复了大量兼容性问题。
- 校验设备连接:执行
adb devices确认两台Pixel设备均处于device状态,无离线或未授权提示,必要时重新插拔USB并授权ADB连接。 - 清理项目缓存:运行
./gradlew clean后重新执行测试,避免旧的插件配置缓存导致冲突。
针对重复跟踪错误
- 更换测试Runner:将命令中的
androidx.test.runner.AndroidJUnitRunner替换为androidx.benchmark.junit4.AndroidBenchmarkRunner,这是基准测试的官方指定Runner,能规避TikTok tracing的冲突问题。 - 移除TikTok tracing依赖:如果项目中集成了TikTok相关的跟踪库,暂时移除该依赖,Baseline Profile生成不需要额外的第三方跟踪工具。
- 关闭第三方无障碍服务:错误提示关联到无障碍事件监听,关闭设备上的第三方无障碍应用,部分此类服务会干扰基准测试的跟踪逻辑。
通用排查点
- 确保设备处于解锁状态,且在开发者选项中开启“保持唤醒状态”,避免测试过程中设备休眠。
- 确认开发者选项中的“USB调试”“仅充电模式下允许ADB调试”已启用。
内容的提问来源于stack exchange,提问作者Carlos Lopez
相关产品推荐
相关产品推荐

