具有baselineprofile宏基准测试的Android应用程序因profileinstaller库问题而失败

问题描述 投票:0回答:1

我试图通过尝试基本配置文件来提高应用程序的性能,但无法运行它。使用 gradle 8.2 配置项目并

'androidx.profileinstaller:profileinstaller:1.3.1'
'androidx.benchmark:benchmark-macro-junit4:1.2.2'

我能够使用模拟器生成baseline-prof.txt,但无法通过运行基准代码片段来测试性能

@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.android",
            metrics = listOf(StartupTimingMetric()),
            compilationMode = compilationMode,
            startupMode = StartupMode.COLD,
            iterations = 1,
            setupBlock = {
                pressHome()
            },
            measureBlock = {
                startActivityAndWait()
                device.wait(Until.hasObject(By.text("Exit")),10_000)
            }
        )
    }
}

基准测试出现以下错误

startupCompilationNone()

java.lang.RuntimeException: The baseline profile install broadcast was not received. This most likely means that the profileinstaller library is missing from the target apk.

startupCompilationBaselineProfiles()

java.lang.IllegalStateException: The DROP_SHADER_CACHE broadcast was not received. This most likely means that the `androidx.profileinstaller` library used by the target apk is old. Please use `1.3.0-alpha02` or newer. For more information refer to the release notes at https://developer.android.com/jetpack/androidx/releases/profileinstaller.

不确定出了什么问题,我正在尝试使用所有最新的可用库,并在禁用电池优化的情况下使用多个设备 Pixel、motoE、OnePlus 进行测试。

非常感谢任何方向的帮助

android performance baseline-profile macrobenchmark compilationmode
1个回答
0
投票

该问题与上述错误无关。测试结果选项卡中的配置文件安装程序问题具有误导性。发现gson中存在proguard TypeToken问题。在 progaurd 中添加以下行解决了问题

-keep class com.google.gson.reflect.TypeToken
-keep class * extends com.google.gson.reflect.TypeToken
-keep public class * implements java.lang.reflect.Type
© www.soinside.com 2019 - 2024. All rights reserved.