93 lines
3.3 KiB
Kotlin
93 lines
3.3 KiB
Kotlin
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")
|
|
}
|
|
|
|
// ============================================================
|
|
// 发布签名配置(正式包)
|
|
//
|
|
// 1. 生成 keystore(一次性,命令在 android/ 目录下执行):
|
|
// keytool -genkey -v -keystore app/upload-keystore.jks ^
|
|
// -keyalg RSA -keysize 2048 -validity 10000 -alias key
|
|
// (会让你设两个密码 + 填公司信息;这两个密码务必保管好,
|
|
// 丢了=正式包永远无法升级,只能换包名重新上架)
|
|
// 2. 把密码填进 android/key.properties(该文件已被 git 忽略,不会泄漏)
|
|
// 3. 填完后执行 flutter build apk --release / flutter build appbundle
|
|
//
|
|
// 兜底:key.properties 不存在或 storeFile 为空时,
|
|
// 自动降级用 debug 签名(仅便于本机安装,不能上架/升级)。
|
|
// ============================================================
|
|
val keystoreProperties = Properties()
|
|
val keystorePropertiesFile = rootProject.file("key.properties")
|
|
val storeFilePath = if (keystorePropertiesFile.exists()) {
|
|
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
|
keystoreProperties.getProperty("storeFile", "")
|
|
} else {
|
|
""
|
|
}
|
|
val hasReleaseKey = keystorePropertiesFile.exists() && storeFilePath.isNotBlank()
|
|
|
|
android {
|
|
namespace = "com.yuanxuan.aixuediebian"
|
|
compileSdk = flutter.compileSdkVersion
|
|
ndkVersion = flutter.ndkVersion
|
|
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_17
|
|
targetCompatibility = JavaVersion.VERSION_17
|
|
isCoreLibraryDesugaringEnabled = true
|
|
}
|
|
|
|
defaultConfig {
|
|
// 应用唯一标识(applicationId)。改了=新包,与旧包不共存。
|
|
// namespace 同此包名(MainActivity.kt 的 package 也保持同步)。
|
|
applicationId = "com.yuanxuan.aixuediebian"
|
|
// You can update the following values to match your application needs.
|
|
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
|
minSdk = flutter.minSdkVersion
|
|
targetSdk = flutter.targetSdkVersion
|
|
versionCode = flutter.versionCode
|
|
versionName = flutter.versionName
|
|
}
|
|
|
|
signingConfigs {
|
|
create("release") {
|
|
if (hasReleaseKey) {
|
|
keyAlias = keystoreProperties.getProperty("keyAlias")
|
|
keyPassword = keystoreProperties.getProperty("keyPassword")
|
|
storeFile = file(storeFilePath)
|
|
storePassword = keystoreProperties.getProperty("storePassword")
|
|
}
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
release {
|
|
// 有正式签名 → 用 release 签名;否则降级 debug 签名(仅便于本地安装调试)
|
|
signingConfig = if (hasReleaseKey) {
|
|
signingConfigs.getByName("release")
|
|
} else {
|
|
signingConfigs.getByName("debug")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
kotlin {
|
|
compilerOptions {
|
|
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
|
}
|
|
}
|
|
|
|
flutter {
|
|
source = "../.."
|
|
}
|
|
|
|
dependencies {
|
|
coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.1.5")
|
|
}
|