98 lines
3.8 KiB
Kotlin
98 lines
3.8 KiB
Kotlin
// 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,
|
||
// 固定为 37(比 Flutter 默认的 36 高一档,只影响编译期 API 可见性)。
|
||
compileSdk = 37
|
||
ndkVersion = flutter.ndkVersion
|
||
|
||
compileOptions {
|
||
sourceCompatibility = JavaVersion.VERSION_17
|
||
targetCompatibility = JavaVersion.VERSION_17
|
||
}
|
||
|
||
defaultConfig {
|
||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||
applicationId = "com.stormg.lumadrama"
|
||
// 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 {
|
||
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 原生库
|
||
ndk {
|
||
abiFilters += listOf("arm64-v8a", "armeabi-v7a")
|
||
}
|
||
// R8 裁剪未使用的 Java/Kotlin 代码与资源,减小 dex 与 res。
|
||
isMinifyEnabled = true
|
||
isShrinkResources = true
|
||
proguardFiles(
|
||
getDefaultProguardFile("proguard-android-optimize.txt"),
|
||
"proguard-rules.pro",
|
||
)
|
||
// 有 upload keystore 时用正式签名,否则回落到 debug 便于本地调试。
|
||
signingConfig = signingConfigs.getByName(if (hasReleaseKeystore) "release" else "debug")
|
||
}
|
||
}
|
||
}
|
||
|
||
kotlin {
|
||
compilerOptions {
|
||
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
||
}
|
||
}
|
||
|
||
// 生产包不允许出现 x86_64:部分插件 AAR 会带入少量 x86_64 原生库,这里显式剔除。
|
||
androidComponents {
|
||
onVariants(selector().withBuildType("release")) { variant ->
|
||
variant.packaging.jniLibs.excludes.add("lib/x86_64/**")
|
||
// 原生库随 APK 压缩存储:下载体积明显小于解压后的体积,代价是安装时解压。
|
||
// 本包 90% 体积是 so,这一项对国内商店的 APK 分发影响最大。
|
||
variant.packaging.jniLibs.useLegacyPackaging = true
|
||
}
|
||
}
|
||
|
||
flutter {
|
||
source = "../.."
|
||
}
|