plugins{id("com.android.test")id("androidx.baselineprofile")}android{defaultConfig{...}// Point to the app module, the module that you're generating the Baseline Profile for.targetProjectPath=":app"// Configure a GMD (optional).testOptions.managedDevices.devices{pixel6Api31(com.android.build.api.dsl.ManagedVirtualDevice){device="Pixel 6"apiLevel=31systemImageSource="aosp"}}}dependencies{...}// Baseline Profile Gradle plugin configuration. Everything is optional. This// example uses the GMD added earlier and disables connected devices.baselineProfile{// Specifies the GMDs to run the tests on. The default is none.managedDevices+="pixel6Api31"// Enables using connected devices to generate profiles. The default is// `true`. When using connected devices, they must be rooted or API 33 and// higher.useConnectedDevices=false}
Groovy
plugins{id'com.android.test'id'androidx.baselineprofile'}android{defaultConfig{...}// Point to the app module, the module that you're generating the Baseline Profile for.targetProjectPath':app'// Configure a GMD (optional).testOptions.managedDevices.devices{pixel6Api31(com.android.build.api.dsl.ManagedVirtualDevice){device'Pixel 6'apiLevel31systemImageSource'aosp'}}}dependencies{...}// Baseline Profile Gradle plugin configuration. Everything is optional. This// example uses the GMD added earlier and disables connected devices.baselineProfile{// Specifies the GMDs to run the tests on. The default is none.managedDevices['pixel6Api31']// Enables using connected devices to generate profiles. The default is// `true`. When using connected devices, they must be rooted or API 33 and// higher.useConnectedDevicesfalse}
plugins{id("com.android.application")id("androidx.baselineprofile")}android{// There are no changes to the `android` block....}dependencies{...// Add a `baselineProfile` dependency on the `:baseline-profile` module.baselineProfile(project(":baseline-profile"))}
Groovy
plugins{id'com.android.application'id'androidx.baselineprofile'}android{// No changes to the `android` block....}dependencies{...// Add a `baselineProfile` dependency on the `:baseline-profile` module.baselineProfile':baseline-profile'}
当您在 Android Studio 中运行测试时,build 输出中会包含基准配置文件带来的速度提升的详细信息:
StartupBenchmarks_startupCompilationBaselineProfiles
timeToInitialDisplayMs min 161.8, median 178.9, max 194.6
StartupBenchmarks_startupCompilationNone
timeToInitialDisplayMs min 184.7, median 196.9, max 202.9