build(android): 支持正式签名配置回退

This commit is contained in:
Zhou Weidong committed 2026-11-17 09:59:25 +08:00
1 parent bcf2dfe02a
commit 814f46da1a
1 file changed
+30 -3
+30 -3
View File
@@ -1,11 +1,24 @@
// Author: fruit.com.cn
import java.io.FileInputStream
import java.util.Properties
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
// 正式包签名信息从 android/key.properties 读取;该文件与 keystore 都已忽略入库。
// 文件缺失时回落到 debug 签名,保证本地 `flutter run --release` 仍可调试。
val keystorePropertiesFile = rootProject.file("key.properties")
val keystoreProperties = Properties()
if (keystorePropertiesFile.exists()) {
FileInputStream(keystorePropertiesFile).use { keystoreProperties.load(it) }
}
val hasReleaseKeystore = keystorePropertiesFile.exists() &&
keystoreProperties.getProperty("storeFile").orEmpty().isNotEmpty()
android {
namespace = "com.stormg.lumadrama"
// permission_handler_android 14 的 AAR 元数据要求依赖方 compileSdk >= 37,
@@ -29,6 +42,21 @@ android {
versionName = flutter.versionName
}
signingConfigs {
if (hasReleaseKeystore) {
create("release") {
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
// Google Play 要求上传包必须使用固定密钥签名,且开启 Play 应用签名后该密钥成为上传密钥。
enableV1Signing = true
enableV2Signing = true
enableV3Signing = true
}
}
}
buildTypes {
release {
// 生产包只保留 arm64-v8a 与 armeabi-v7a,避免插件带入 x86_64 原生库
@@ -42,9 +70,8 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
// 有 upload keystore 时用正式签名,否则回落到 debug 便于本地调试。
signingConfig = signingConfigs.getByName(if (hasReleaseKeystore) "release" else "debug")
}
}
}