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:
parent
18ac1f5c43
commit
a86131471c
|
|
@ -44,6 +44,9 @@ app.*.map.json
|
||||||
/android/app/profile
|
/android/app/profile
|
||||||
/android/app/release
|
/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!)
|
# Release signing keys (IMPORTANT: never commit these!)
|
||||||
/publish/
|
/publish/
|
||||||
*.keystore
|
*.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")
|
||||||
|
|
@ -15,6 +16,33 @@ if (keyPropertiesFile.exists()) {
|
||||||
keyProperties.load(FileInputStream(keyPropertiesFile))
|
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 {
|
android {
|
||||||
namespace = "com.rwadurian.rwa_android_app"
|
namespace = "com.rwadurian.rwa_android_app"
|
||||||
compileSdk = flutter.compileSdkVersion
|
compileSdk = flutter.compileSdkVersion
|
||||||
|
|
@ -36,8 +64,9 @@ android {
|
||||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||||
minSdk = flutter.minSdkVersion
|
minSdk = flutter.minSdkVersion
|
||||||
targetSdk = flutter.targetSdkVersion
|
targetSdk = flutter.targetSdkVersion
|
||||||
versionCode = flutter.versionCode
|
// Auto-incremented version code and name
|
||||||
versionName = flutter.versionName
|
versionCode = autoVersionCode
|
||||||
|
versionName = getAutoVersionName()
|
||||||
}
|
}
|
||||||
|
|
||||||
signingConfigs {
|
signingConfigs {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue