Add auto updating version code

This commit is contained in:
izzy2lost
2025-09-22 04:51:39 -04:00
parent aa3fed2b0a
commit 150c377c2c
3 changed files with 53 additions and 1 deletions
+1
View File
@@ -21,3 +21,4 @@ build/
*.exe
/WARP.md
*.aab
*.properties
+50 -1
View File
@@ -2,6 +2,29 @@ plugins {
id 'com.android.application'
}
// Function to get and increment version code
def getVersionCode() {
def versionFile = file('version.properties')
def versionCode = 3 // Starting version code
if (versionFile.exists()) {
def props = new Properties()
props.load(new FileInputStream(versionFile))
versionCode = props['VERSION_CODE'] as int
}
// Increment version code for AAB builds
if (gradle.startParameter.taskNames.any { it.toLowerCase().contains('bundle') }) {
versionCode++
def props = new Properties()
props['VERSION_CODE'] = versionCode.toString()
props.store(versionFile.newWriter(), null)
println "Auto-incremented version code to: ${versionCode}"
}
return versionCode
}
android {
namespace 'com.izzy2lost.psx2'
compileSdk 36
@@ -11,7 +34,7 @@ android {
applicationId "com.izzy2lost.psx2"
minSdk 26
targetSdk 36
versionCode 2
versionCode getVersionCode()
versionName "1.0.1"
// APK
setProperty("archivesBaseName","PSX2_${versionCode}_${new Date().format('yyyyMMddHHmm')}")
@@ -67,6 +90,32 @@ android {
}
}
// Manual version increment tasks
task incrementVersion {
doLast {
def versionFile = file('version.properties')
def versionCode = 3
if (versionFile.exists()) {
def props = new Properties()
props.load(new FileInputStream(versionFile))
versionCode = props['VERSION_CODE'] as int
}
versionCode++
def props = new Properties()
props['VERSION_CODE'] = versionCode.toString()
props.store(versionFile.newWriter(), null)
println "Incremented version code to: ${versionCode}"
}
}
task showVersion {
doLast {
println "Current version code: ${getVersionCode()}"
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.7.1'
implementation 'com.google.android.material:material:1.14.0-alpha04'
+2
View File
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:versionCode="1"
android:versionName="1.0"
android:installLocation="preferExternal"
tools:ignore="MissingLeanbackLauncher">