feat(android): APK versionCode 自动递增 — 每次编译自增,各环境独立计数
参考 rwadurian mobile-app 的 version.properties 方案,为 genex-mobile 和 admin-app 添加 build 时 versionCode 自动 +1 逻辑: - build.gradle.kts: calculateNextVersionCode() 读取 version.properties, 自增后写回;versionName 格式 "pubspec版本.buildNumber"(如 1.0.0.42) - .gitignore: 排除 /android/app/version.properties,每个构建环境 (本机、CI、服务器)各自维护独立计数器,互不干扰 - 首次编译从 1 开始,后续跨日期持续递增,保证 APK 版本始终唯一 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fcf49b5257
commit
0cd5c58ecb
|
|
@ -44,6 +44,9 @@ app.*.map.json
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
|
# Auto-generated version code (each build environment maintains its own counter)
|
||||||
|
/android/app/version.properties
|
||||||
|
|
||||||
# Signing keys (do NOT commit to public repos)
|
# Signing keys (do NOT commit to public repos)
|
||||||
android/key.properties
|
android/key.properties
|
||||||
android/app/keystore/
|
android/app/keystore/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
|
|
@ -14,6 +15,30 @@ if (keystorePropertiesFile.exists()) {
|
||||||
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
val autoVersionCode = calculateNextVersionCode()
|
||||||
|
|
||||||
|
fun getAutoVersionName(): String {
|
||||||
|
val flutterVersionName = flutter.versionName
|
||||||
|
return "$flutterVersionName.$autoVersionCode"
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "cn.gogenex.genex_issuer"
|
namespace = "cn.gogenex.genex_issuer"
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
|
|
@ -32,8 +57,8 @@ android {
|
||||||
applicationId = "cn.gogenex.issuer"
|
applicationId = "cn.gogenex.issuer"
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
targetSdk = flutter.targetSdkVersion
|
targetSdk = flutter.targetSdkVersion
|
||||||
versionCode = flutter.versionCode
|
versionCode = autoVersionCode
|
||||||
versionName = flutter.versionName
|
versionName = getAutoVersionName()
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ app.*.map.json
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/android/app/release
|
||||||
|
|
||||||
|
# Auto-generated version code (each build environment maintains its own counter)
|
||||||
|
/android/app/version.properties
|
||||||
|
|
||||||
# Signing keys (do NOT commit to public repos)
|
# Signing keys (do NOT commit to public repos)
|
||||||
android/key.properties
|
android/key.properties
|
||||||
android/app/keystore/
|
android/app/keystore/
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import java.util.Properties
|
import java.util.Properties
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.android.application")
|
id("com.android.application")
|
||||||
|
|
@ -14,6 +15,30 @@ if (keystorePropertiesFile.exists()) {
|
||||||
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
val autoVersionCode = calculateNextVersionCode()
|
||||||
|
|
||||||
|
fun getAutoVersionName(): String {
|
||||||
|
val flutterVersionName = flutter.versionName
|
||||||
|
return "$flutterVersionName.$autoVersionCode"
|
||||||
|
}
|
||||||
|
|
||||||
android {
|
android {
|
||||||
namespace = "cn.gogenex.genex_consumer"
|
namespace = "cn.gogenex.genex_consumer"
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
|
|
@ -33,8 +58,8 @@ android {
|
||||||
applicationId = "cn.gogenex.consumer"
|
applicationId = "cn.gogenex.consumer"
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
targetSdk = flutter.targetSdkVersion
|
targetSdk = flutter.targetSdkVersion
|
||||||
versionCode = flutter.versionCode
|
versionCode = autoVersionCode
|
||||||
versionName = flutter.versionName
|
versionName = getAutoVersionName()
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue