rwadurian/frontend/mining-app/android/app/build.gradle.kts

89 lines
2.6 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import java.util.Properties
import java.io.FileInputStream
import java.io.FileOutputStream
plugins {
id("com.android.application")
id("kotlin-android")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
// ============================================
// Auto-increment version code on each build
// ============================================
val versionPropertiesFile = rootProject.file("app/version.properties")
val versionProperties = Properties()
fun calculateNextVersionCode(): Int {
if (versionPropertiesFile.exists()) {
versionProperties.load(FileInputStream(versionPropertiesFile))
}
val currentCode = versionProperties.getProperty("VERSION_CODE", "0").toInt()
val newCode = currentCode + 1
versionProperties.setProperty("VERSION_CODE", newCode.toString())
versionProperties.store(FileOutputStream(versionPropertiesFile), "Auto-generated version code - DO NOT EDIT MANUALLY")
return newCode
}
// Get auto-incremented version code
val autoVersionCode = calculateNextVersionCode()
// Version name format: major.minor.patch (from pubspec.yaml) + build number
// Example: 1.0.0.123
fun getAutoVersionName(): String {
val flutterVersionName = flutter.versionName
return "$flutterVersionName.$autoVersionCode"
}
android {
namespace = "com.rwadurian.mining_app"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}
defaultConfig {
applicationId = "com.rwadurian.mining_app"
minSdk = 24
targetSdk = flutter.targetSdkVersion
// Auto-incremented version code and name
versionCode = autoVersionCode
versionName = getAutoVersionName()
// 多dex支持
multiDexEnabled = true
}
buildTypes {
debug {
// Debug配置
isDebuggable = true
applicationIdSuffix = ".debug"
versionNameSuffix = "-debug"
}
release {
// Release配置
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
// 暂时使用debug签名后续配置正式签名
signingConfig = signingConfigs.getByName("debug")
}
}
}
flutter {
source = "../.."
}