此设备版本不支持基线配置文件

Pau*_*nko 14 android baseline-profile

我配置了一个基准测试模块并为项目创建了一个基线配置文件,并根据此处的说明将其保存在应用程序中https://developer.android.com/studio/profile/baselineprofiles

我还添加了基准:

@RunWith(AndroidJUnit4::class)
class BaselineProfileBenchmark {
    @get:Rule
    val benchmarkRule = MacrobenchmarkRule()

    @Test
    fun startupNoCompilation() {
        startup(CompilationMode.None())
    }

    @Test
    fun startupBaselineProfile() {
        startup(
            CompilationMode.Partial(
                baselineProfileMode = BaselineProfileMode.Require
            )
        )
    }

    private fun startup(compilationMode: CompilationMode) {
        benchmarkRule.measureRepeated(
            packageName = "com.example.app",
            metrics = listOf(StartupTimingMetric()),
            iterations = 10,
            startupMode = StartupMode.COLD,
            compilationMode = compilationMode
        ) {
            pressHome()
            startActivityAndWait()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

startupBaselineProfile()测试失败,并出现异常“此设备版本不支持基线配置文件”。我尝试在具有最新 Android 版本的不同 Pixel 和 Samsung 设备上运行它,但到处都会抛出相同的异常。

这些基线配置文件真的有效吗?

mly*_*yko 13

2022 年 10 月更新

使用解决问题的androidx.profileinstaller版本或更高版本(或发布时)。1.3.0-alpha011.2.1

原答案

目前基线配置文件存在一些已知问题:

  • 无法在 Android 12L (Api 32) 上对它们进行基准测试 - b/228222110
  • 您需要最新的 alpha 版本的 profileinstaller,即 1.2.0-alpha02

请注意,profileinstaller 可能会添加一个库(例如 jetpack compose),因此请确保将其添加到依赖项中以覆盖版本。