feat(mobile-app): auto-increment version code on each build

- Add version.properties file to track build number locally
- Auto-increment versionCode on every debug/release build
- Version name format: major.minor.patch.buildNumber (e.g., 1.0.0.123)
- Add version.properties to .gitignore (each developer has own build number)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-09 00:59:20 -08:00
parent 18ac1f5c43
commit a86131471c
2 changed files with 34 additions and 2 deletions

View File

@ -44,6 +44,9 @@ app.*.map.json
/android/app/profile
/android/app/release
# Auto-generated version file (each developer has their own build number)
/android/app/version.properties
# Release signing keys (IMPORTANT: never commit these!)
/publish/
*.keystore

View File

@ -1,5 +1,6 @@
import java.util.Properties
import java.io.FileInputStream
import java.io.FileOutputStream
plugins {
id("com.android.application")
@ -15,6 +16,33 @@ if (keyPropertiesFile.exists()) {
keyProperties.load(FileInputStream(keyPropertiesFile))
}
// ============================================
// Auto-increment version code on each build
// ============================================
val versionPropertiesFile = rootProject.file("app/version.properties")
val versionProperties = Properties()
fun getAutoVersionCode(): 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 = getAutoVersionCode()
// Version name format: major.minor.patch (from pubspec.yaml) + build number
// Example: 1.0.0.123
fun getAutoVersionName(): String {
val flutterVersionName = flutter.versionName ?: "1.0.0"
return "$flutterVersionName.$autoVersionCode"
}
android {
namespace = "com.rwadurian.rwa_android_app"
compileSdk = flutter.compileSdkVersion
@ -36,8 +64,9 @@ android {
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = flutter.minSdkVersion
targetSdk = flutter.targetSdkVersion
versionCode = flutter.versionCode
versionName = flutter.versionName
// Auto-incremented version code and name
versionCode = autoVersionCode
versionName = getAutoVersionName()
}
signingConfigs {