fix android

This commit is contained in:
2025-07-22 01:35:20 +08:00
parent 03914ecdd9
commit f407acd9bc

View File

@@ -1,3 +1,6 @@
import java.io.FileInputStream
import java.util.Properties
plugins {
id("com.android.application")
id("kotlin-android")
@@ -5,6 +8,13 @@ plugins {
id("dev.flutter.flutter-gradle-plugin")
}
val keyPropertiesFile = rootProject.file("key.properties")
val keyProperties = Properties()
if (keyPropertiesFile.exists()) {
// 如果文件存在,则加载其中的内容。
keyProperties.load(FileInputStream(keyPropertiesFile))
}
android {
namespace = "cn.staredges.swiftcat"
compileSdk = flutter.compileSdkVersion
@@ -19,6 +29,17 @@ android {
jvmTarget = JavaVersion.VERSION_11.toString()
}
signingConfigs {
// 创建一个名为 'release' 的签名配置。
// 只有当 key.properties 文件存在时,这里的配置才会有实际值。
create("release") {
keyAlias = keyProperties["keyAlias"] as String?
keyPassword = keyProperties["keyPassword"] as String?
storeFile = if (keyProperties["storeFile"] != null) file(keyProperties["storeFile"] as String) else null
storePassword = keyProperties["storePassword"] as String?
}
}
defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId = "cn.staredges.swiftcat"
@@ -32,9 +53,14 @@ android {
buildTypes {
release {
// 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")
if (keyPropertiesFile.exists() && keyProperties.containsKey("storeFile")) {
// 如果文件存在且包含必要信息,则使用上面定义的 'release' 签名配置。
signingConfig = signingConfigs.getByName("release")
} else {
// 如果文件不存在(这是开发者本地的常见情况),则回退到使用默认的 'debug' 签名。
// 这样做可以确保即使没有配置发布密钥,`flutter run --release` 也能成功运行。
signingConfig = signingConfigs.getByName("debug")
}
}
}
}