yayacal/macrobenchmark/build.gradle.kts
xfy 2771e3733b perf: 集成 Macrobenchmark 模块,自动生成全量 Baseline Profile
- 新增 :macrobenchmark 模块,提供自动 Baseline Profile 生成
- 扩展 proguard-rules.pro,保留所有业务类方法名确保 profile 匹配
- 全量 AOT 覆盖:冷启动 + 交互路径(年视图、周折叠、关于页等)
- app/build.gradle.kts 新增 benchmark 构建类型
- README 简化 Baseline Profiles 维护指南

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 10:50:01 +08:00

88 lines
2.9 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

plugins {
id("com.android.test")
}
android {
namespace = "plus.rua.project.macrobenchmark"
compileSdk = libs.versions.android.compileSdk.get().toInt()
defaultConfig {
minSdk = libs.versions.android.minSdk.get().toInt()
targetSdk = libs.versions.android.targetSdk.get().toInt()
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
buildTypes {
// benchmark 构建类型必须与 app 模块的 release 类型签名一致
create("benchmark") {
isDebuggable = true
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("release")
}
}
targetProjectPath = ":app"
experimentalProperties["android.experimental.self-instrumenting"] = true
}
dependencies {
implementation(libs.androidx.benchmark.macro)
implementation(libs.androidx.test.ext.junit)
implementation(libs.androidx.test.espresso)
implementation(libs.androidx.test.uiautomator)
}
// ===== Baseline Profile 自动复制 =====
// 运行 ./gradlew :macrobenchmark:updateBaselineProfile 即可一键生成并复制
val updateBaselineProfile by tasks.registering {
group = "benchmark"
description = "运行 connectedBenchmarkAndroidTest 并将生成的 baseline-prof.txt 复制到 :core 模块"
// 依赖基准测试 task需要先连接设备/模拟器)
dependsOn("connectedBenchmarkAndroidTest")
doLast {
// 寻找生成的 profile 文件(路径格式因设备/Gradle 版本略有不同)
val sourcePaths = listOf(
// AGP 8.x+ 标准输出路径
"build/outputs/connected_android_test_additional_output/benchmark/",
"build/outputs/connected_android_test_additional_output/",
)
val targetFile = rootProject.projectDir.resolve("core/src/main/baseline-prof.txt")
var copied = false
for (path in sourcePaths) {
val dir = file(path)
if (!dir.exists()) continue
val profileFile = dir.walkTopDown()
.firstOrNull { it.name == "baseline-prof.txt" }
?: continue
profileFile.copyTo(targetFile, overwrite = true)
println("✅ Baseline Profile 已自动复制到: ${targetFile.absolutePath}")
println(" 来源: ${profileFile.absolutePath}")
copied = true
break
}
if (!copied) {
throw GradleException(
"未找到生成的 baseline-prof.txt。\n" +
"请确认:\n" +
" 1. 设备/模拟器已连接 (adb devices)\n" +
" 2. 应用已安装在 benchmark 构建类型下\n" +
" 3. 检查 macrobenchmark/build/outputs/ 下是否有输出"
)
}
}
}