96 lines
3.3 KiB
Kotlin
96 lines
3.3 KiB
Kotlin
import com.android.build.VariantOutput
|
|
import com.android.build.gradle.AbstractAppExtension
|
|
import com.android.build.gradle.api.ApkVariantOutput
|
|
import java.io.FileInputStream
|
|
import java.time.LocalDate
|
|
import java.time.format.DateTimeFormatter
|
|
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")
|
|
}
|
|
|
|
// 读取签名配置
|
|
val keystoreProperties = Properties()
|
|
val keystorePropertiesFile = rootProject.file("key.properties")
|
|
if (keystorePropertiesFile.exists()) {
|
|
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
|
}
|
|
|
|
android {
|
|
namespace = "com.ttstd.familycare"
|
|
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.ttstd.familycare"
|
|
// 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 = 37
|
|
versionCode = flutter.versionCode
|
|
versionName = flutter.versionName
|
|
}
|
|
|
|
signingConfigs {
|
|
create("own") {
|
|
keyAlias = keystoreProperties["keyAlias"] as String?
|
|
keyPassword = keystoreProperties["keyPassword"] as String?
|
|
storeFile = keystoreProperties["storeFile"]?.let { file(it) }
|
|
storePassword = keystoreProperties["storePassword"] as String?
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
debug {
|
|
if (keystorePropertiesFile.exists()) {
|
|
signingConfig = signingConfigs.getByName("own")
|
|
}
|
|
}
|
|
release {
|
|
// 使用自有签名配置
|
|
signingConfig = signingConfigs.getByName("own")
|
|
}
|
|
}
|
|
|
|
packaging {
|
|
jniLibs {
|
|
// liblocSDK8b.so 使用自定义 ELF 布局,AGP 的 strip 会重写其节头表并丢失 .dynamic,
|
|
// 导致运行时请求串解密失败(getLocType() 返回 162)。必须原样打包。
|
|
keepDebugSymbols += "**/liblocSDK8b.so"
|
|
}
|
|
}
|
|
}
|
|
|
|
flutter {
|
|
source = "../.."
|
|
}
|
|
|
|
// 自定义 APK 输出文件名:{应用英文}_{版本号}_{构建日期}_{abi}.apk
|
|
// 例:ttstd_family_care_v1.0.0_20261105_arm64-v8a.apk
|
|
// 未按 ABI 拆分时 abi 为 universal。
|
|
val appEnglishName = "ttstd_family_care"
|
|
val buildDate = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE)
|
|
|
|
// AGP 新 Variant API 不提供修改输出文件名的能力,只能走仍可用的旧 API(Flutter 插件自身也依赖它)。
|
|
@Suppress("DEPRECATION")
|
|
val legacyAndroidExtension = extensions.getByName("android") as AbstractAppExtension
|
|
legacyAndroidExtension.applicationVariants.configureEach {
|
|
outputs.forEach { output ->
|
|
val apkOutput = output as ApkVariantOutput
|
|
val abi = apkOutput.getFilter(VariantOutput.FilterType.ABI)
|
|
?.takeIf { it.isNotEmpty() }
|
|
?: "universal"
|
|
apkOutput.outputFileName =
|
|
"${appEnglishName}_v${flutter.versionName}_${buildDate}_${abi}.apk"
|
|
}
|
|
}
|