基线配置文件 - 生成版本时出现问题 BaselineProfile

J.A*_*oyo 8 performance android baseline-profile

我正在尝试为我的应用程序实现基线配置文件官方文档)。按照本视频(通过基线配置文件提高性能)中指示的步骤,如果我使用DebugBuildVariant,我可以创建benchmark-prof.txt文件以缩短启动时间。但是当我尝试创建用于发布的基线-prof 文件时,出现以下异常:

./gradlew :macrobenchmark:pixel2Api31BenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.class=com.example.BaselineProfileGenerator
Run Code Online (Sandbox Code Playgroud)
com.example.BaselineProfileGenerator > generate[pixel2Api31] FAILED
        java.lang.IllegalStateException: Unable to confirm activity launch completion [] Please report a bug with the output of `adb shell dumpsys gfxinfo com.leinardi.forlago framestats`
                at androidx.benchmark.macro.MacrobenchmarkScope.startActivityImpl(MacrobenchmarkScope.kt:179)
Tests on pixel2Api31 failed: There was 1 failure(s).
Run Code Online (Sandbox Code Playgroud)

这就是我们的BaselineProfileGenerator的样子:

./gradlew :macrobenchmark:pixel2Api31BenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.class=com.example.BaselineProfileGenerator
Run Code Online (Sandbox Code Playgroud)

如果我配置调试基准,它会很好地工作:

benchmark {
    initWith buildTypes.debug
    signingConfig signingConfigs.debug
    matchingFallbacks = ['debug']
    debuggable false
    proguardFiles('benchmark-rules.pro')
}
Run Code Online (Sandbox Code Playgroud)

但是将其配置为Release,当您尝试生成它时,基准测试会引发之前的异常。

benchmark {
    initWith buildTypes.release
    signingConfig signingConfigs.debug
    matchingFallbacks = ['release']
    debuggable false
    proguardFiles('benchmark-rules.pro')
}

Run Code Online (Sandbox Code Playgroud)

使用的组件:基线配置文件

使用的版本: AGP=7.3.0-rc01、uiautomator=2.2.0 & benchmark-macro-junit4=1.1.0

设备/Android 版本转载于:

testOptions {
        managedDevices {
            devices {
                pixel2Api31(com.android.build.api.dsl.ManagedVirtualDevice) {
                    device = "Pixel 2"
                    apiLevel = 31
                    systemImageSource = "aosp"
                }
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

在 Google 问题跟踪器上报告: 问题

触发该问题的示例项目: https ://github.com/leinardi/Forlago/tree/baseline-profiles

小智 1

SplashScreen.setKeepOnScreenCondition在活动中使用过吗?如果是,注释掉该行可能会有所帮助。
如果当前构建类型是 ,您可以禁用它benchmark

if (!BuildConfig.BUILD_TYPE.contains("benchmark")) {
    splashScreen.setKeepOnScreenCondition { ... }
}
Run Code Online (Sandbox Code Playgroud)