I am trying to implement the Baseline profiles(official documentation) for my app. Following the steps indicated in this video(Improving Performance with Baseline Profiles) if I use the DebugBuildVariant I am able to create the baseline-prof.txt file to improve the startup time . But when I try to create the baseline-prof file for release I have this exception:
./gradlew :macrobenchmark:pixel2Api31BenchmarkAndroidTest -P android.testInstrumentationRunnerArguments.class=com.example.BaselineProfileGenerator
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).
This is how it looks like our BaselineProfileGenerator:
@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate() {
rule.collectBaselineProfile("com.leinardi.forlago") {
pressHome()
startActivityAndWait()
}
}
}
If I configure the benchmark for Debug it works well:
benchmark {
initWith buildTypes.debug
signingConfig signingConfigs.debug
matchingFallbacks = ['debug']
debuggable false
proguardFiles('benchmark-rules.pro')
}
But configuring it for Release, benchmark throws the previous exception when you try to generate it.
benchmark {
initWith buildTypes.release
signingConfig signingConfigs.debug
matchingFallbacks = ['release']
debuggable false
proguardFiles('benchmark-rules.pro')
}
Component used: Baseline Profiles
Version used: AGP=7.3.0-rc01, uiautomator=2.2.0 & benchmark-macro-junit4=1.1.0
Devices/Android versions reproduced on:
testOptions {
managedDevices {
devices {
pixel2Api31(com.android.build.api.dsl.ManagedVirtualDevice) {
device = "Pixel 2"
apiLevel = 31
systemImageSource = "aosp"
}
}
}
}
Reported on Google Issue tracker: issue
Sample project to trigger the issue: https://github.com/leinardi/Forlago/tree/baseline-profiles