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

OPPO A53(Android12)startupCompilationBaselineProfiles测试异常排查

OPPO A53(ColorOS 12.1)上基准测试CompilationMode.Partial失败问题排查

问题场景

我在Android 12 ColorOS 12.1 OPPO A53设备上运行以下基准测试代码:

package com.google.baselineprofile

import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
@LargeTest
class StartupBenchmarks {

    @get:Rule
    val rule = MacrobenchmarkRule()

    @Test
    fun startupCompilationNone() =
        benchmark(CompilationMode.None())

    @Test
    fun startupCompilationBaselineProfiles() =
        benchmark(CompilationMode.Partial(BaselineProfileMode.Require))

    private fun benchmark(compilationMode: CompilationMode) {
        rule.measureRepeated(
            packageName = "com.example.baselineprofiles_codelab",
            metrics = listOf(StartupTimingMetric()),
            compilationMode = compilationMode,
            startupMode = StartupMode.COLD,
            iterations = 10,
            setupBlock = {
                pressHome()
            },
            measureBlock = {
                startActivityAndWait()
                waitForAsyncContent()
            }
        )
    }
}

报错情况

在该设备上,startupCompilationBaselineProfiles测试失败,抛出错误如下:

java.lang.IllegalStateException: Failed to compile (out=Error: Failed to compile !)
    at androidx.benchmark.macro.CompilationMode$Companion.cmdPackageCompile$benchmark_macro_release(CompilationMode.kt:434)
    at androidx.benchmark.macro.CompilationMode$Partial.compileImpl$benchmark_macro_release(CompilationMode.kt:307)
    at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:114)
    at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release$default(CompilationMode.kt:75)
    at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmark(Macrobenchmark.kt:237)
    at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmarkWithStartupMode(Macrobenchmark.kt:436)
    at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated(MacrobenchmarkRule.kt:107)
    at com.google.baselineprofile.StartupBenchmarks.benchmark(StartupBenchmarks.kt:49)

而startupCompilationNone测试在同一设备上可正常运行,且两个测试在其他设备上均无报错。

附加信息

  • 设备: OPPO A53
  • 系统版本: Android 12 (ColorOS 12.1)
  • 报错测试: startupCompilationBaselineProfiles
  • 正常测试: startupCompilationNone

问题

请问该问题为何会在OPPO A53设备上出现?是否是该设备或ColorOS的特定问题导致CompilationMode.Partial测试失败?如何修复或规避该问题?


原因分析

该问题属于ColorOS 12.1的定制化兼容问题:OPPO对Android原生ART编译机制做了私有修改,加入了自研的内存优化、编译加速逻辑,导致Benchmark库调用的cmdPackageCompile命令执行失败,尤其是针对Baseline Profile的部分编译(Partial Compilation)流程与ColorOS的定制逻辑冲突。

修复/规避方案

  1. 检查开发者选项配置

    • 打开设备开发者选项,确保「ART编译优化」「使用基线配置文件编译应用」相关选项处于开启状态
    • 关闭可能干扰编译的OPPO专属功能,比如「内存拓展」「应用速冻」
  2. 降级Benchmark库版本
    部分新版本Benchmark库对定制系统兼容性较差,可尝试降级到androidx.benchmark:benchmark-macro-junit4:1.1.0或更早的稳定版本,适配ColorOS的编译逻辑。

  3. 跳过特定设备的测试
    在测试代码中通过设备型号判断,跳过OPPO A53上的startupCompilationBaselineProfiles测试:

    @Test
    fun startupCompilationBaselineProfiles() {
        if (android.os.Build.MODEL.equals("OPPO A53", ignoreCase = true)) {
            return // 跳过该设备的Partial Compilation测试
        }
        benchmark(CompilationMode.Partial(BaselineProfileMode.Require))
    }
    
  4. 手动编译排查细节
    通过ADB命令手动执行编译,获取更详细的错误日志:

    adb shell cmd package compile -f -m speed-profile com.example.baselineprofiles_codelab
    

    若命令失败,可通过adb logcat查看系统日志,定位ColorOS的具体限制。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 21:04:56