From 7f9ce7aed8f6f837378cd1742c11a831fb461122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A0=81=E5=86=9C=E9=98=BF=E6=A5=A0?= Date: Fri, 16 Oct 2026 13:23:53 +0800 Subject: [PATCH] =?UTF-8?q?chore(build):=20APK=20=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E8=A7=84=E8=8C=83=202fair-<=E7=89=88=E6=9C=AC>-.apk,?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E5=8D=95=E7=82=B9=E7=BB=B4=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit androidComponents 统一重命名产物,release 省略构建类型,debug 带 -debug 后缀; versionCode/versionName 提升为 build 脚本顶部变量,升版只改一处 --- README.md | 2 +- app/build.gradle.kts | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d5cb532..0091075 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ EOF git tag vX.Y.Z && git push origin vX.Y.Z ``` -产物在 `app/build/outputs/apk/release/`,按设备 ABI 选择(绝大多数设备用 `arm64-v8a`)。 +产物在 `app/build/outputs/apk/release/`,命名规范 `2fair-<版本>-.apk`(如 `2fair-0.1.0-arm64-v8a.apk`),文件名自带 ABI 子串,符合应用内更新择包约定。绝大多数设备用 `arm64-v8a`。 应用内更新依赖发版约定: diff --git a/app/build.gradle.kts b/app/build.gradle.kts index fdf6be9..dad3a57 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -1,5 +1,10 @@ +import com.android.build.api.variant.FilterConfiguration import java.util.Properties +// 版本单点维护:defaultConfig 与 APK 命名共用 +val appVersionCode = 2 +val appVersionName = "0.1.0" + plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.compose) @@ -21,8 +26,8 @@ android { applicationId = "cn.airnan.a2fair" minSdk = 24 targetSdk = 36 - versionCode = 2 - versionName = "0.1.0" + versionCode = appVersionCode + versionName = appVersionName testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" @@ -87,6 +92,24 @@ android { } } +// APK 命名规范:2fair-<版本>-.apk(非 release 附构建类型,如 2fair-0.1.0-debug-arm64-v8a.apk) +androidComponents { + onVariants { variant -> + val buildType = variant.buildType + variant.outputs.forEach { output -> + val abi = output.filters + .firstOrNull { it.filterType == FilterConfiguration.FilterType.ABI }?.identifier + val fileName = buildString { + append("2fair-").append(appVersionName) + abi?.let { append('-').append(it) } + if (buildType != "release") append('-').append(buildType) + append(".apk") + } + output.outputFileName.set(fileName) + } + } +} + dependencies { implementation(platform(libs.androidx.compose.bom)) implementation(libs.reorderable)