新增 Baseline Profile 增加冷启动性能

This commit is contained in:
HapeLee committed 2026-05-13 18:14:40 +08:00
1 parent c1f7faf050
commit accd3afbbb
6 files changed
+218

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
import com.android.build.api.dsl.ManagedVirtualDevice
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.baselineprofile)
}
android {
namespace = "io.legado.baselineprofile"
compileSdk {
version = release(36) {
minorApiLevel = 1
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
defaultConfig {
minSdk = 28
targetSdk = 36
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
targetProjectPath = ":app"
flavorDimensions += listOf("mode")
productFlavors {
create("app") { dimension = "mode" }
}
// This code creates the gradle managed device used to generate baseline profiles.
// To use GMD please invoke generation through the command line:
// ./gradlew :app:generateBaselineProfile
testOptions.managedDevices.allDevices {
create<ManagedVirtualDevice>("pixel6Api34") {
device = "Pixel 6"
apiLevel = 34
systemImageSource = "google"
}
}
}
// This is the configuration block for the Baseline Profile plugin.
// You can specify to run the generators on a managed devices or connected devices.
baselineProfile {
managedDevices += "pixel6Api34"
useConnectedDevices = false
}
dependencies {
implementation(libs.androidx.benchmark.macro.junit4)
implementation(libs.androidx.espresso.core)
implementation(libs.androidx.junit)
implementation(libs.androidx.uiautomator)
}
androidComponents {
onVariants { v ->
val artifactsLoader = v.artifacts.getBuiltArtifactsLoader()
v.instrumentationRunnerArguments.put(
"targetAppId",
v.testedApks.map { artifactsLoader.load(it)?.applicationId }
)
}
}