基线配置文件-生成发布基线配置文件时出现问题



我正在尝试为我的应用程序实现基线配置文件(官方文档(。按照本视频中指示的步骤(使用基线配置文件提高性能(,如果我使用DebugBuildVariant,我可以创建Baseline-prof.txt文件以缩短启动时间。但当我试图创建发布的基线prof文件时,我有一个例外:

./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).

这就是我们的BaselineProfileGenerator:

@OptIn(ExperimentalBaselineProfilesApi::class)
@RunWith(AndroidJUnit4ClassRunner::class)
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate() {
rule.collectBaselineProfile("com.leinardi.forlago") {
pressHome()
startActivityAndWait()
}
}
}

如果我为Debug配置基准测试,它运行良好:

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

但是为Release配置它时,基准测试会在您尝试生成它时抛出上一个异常。

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

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

使用的版本:AGP=7.3.0-rc01,uiautomator=2.2.0&基准标记-百万单位4=1.1.0

设备/安卓版本复制于:

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

在谷歌问题跟踪器上报告:问题

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

我检查了示例代码,看起来问题不在库中,而是在示例项目本身中。

您在应用程序启动期间遇到异常,因为FirebaseCrashlytics未在版本构建类型中初始化

FATAL EXCEPTION: main
Process: com.leinardi.forlago, PID: 4684
java.lang.IllegalStateException: Default FirebaseApp is not initialized in this process com.leinardi.forlago. Make sure to call FirebaseApp.initializeApp(Context) first.
at com.google.firebase.FirebaseApp.getInstance(FirebaseApp.java:47)
at com.leinardi.forlago.library.logging.CrashlyticsTree.log(CrashlyticsTree.kt:15)
at timber.log.Timber$Tree.prepareLog(Timber.kt:97)
at timber.log.Timber$Tree.e(Timber.kt:3)
at timber.log.Timber$Forest.e(Timber.kt:6)
at com.leinardi.forlago.library.android.interactor.android.GetAppUpdateInfoInteractor$invoke$2.invokeSuspend(GetAppUpdateInfoInteractor.kt:181)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:9)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:99)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:12)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:3)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:82)
Suppressed: kotlinx.coroutines.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@c988cf0, Dispatchers.Main.immediate]

一旦我注释掉CrashlyticsTree,配置文件就会正确生成。

您在活动中使用过SplashScreen.setKeepOnScreenCondition吗?如果是的话,评论一下这句话可能会有所帮助
如果当前生成类型为benchmark,则可以禁用它。

if (!BuildConfig.BUILD_TYPE.contains("benchmark")) {
splashScreen.setKeepOnScreenCondition { ... }
}

如果在profileBlock字段中使用pressHome(),则将其删除。仅使用startActivityAndWait。如果您使用自定义ui测试,请使用startActivityAndWait和pressHome正确生成配置文件:(

生成基线配置文件需要非模糊构建。查看此处

最新更新