Colton Idle
01/25/2024, 8:15 PMStefan Oltmann
01/25/2024, 8:27 PMRussell Stewart
01/25/2024, 9:09 PMgradle.properties
is probably the easiest solution. In fact, I'll do you one better. This is what I usually do in my projects:
`gradle.properties`:
majorVersion=1
minorVersion=0
patchVersion=0
testVersion=94
`build.gradle.kts`:
val majorVersion = (findProperty("majorVersion") as String).toInt()
val minorVersion = (findProperty("minorVersion") as String).toInt()
val patchVersion = (findProperty("patchVersion") as String).toInt()
val testVersion = (findProperty("testVersion") as String).toInt()
versionCode = (majorVersion * 100000) + (minorVersion * 1000) + (patchVersion * 100) + testVersion
versionName = if (testVersion > 0) {
"${majorVersion}.${minorVersion}.${patchVersion}.${testVersion}"
} else {
"${majorVersion}.${minorVersion}.${patchVersion}"
}
That way the versionCode
is automatically derived from the versionName
. So, for example, version 1.0.0.94 has a versionCode of 100094. This way all you need to do is bump the minor or patch version number in gradle.properties
and everything else is taken care of.Colton Idle
01/25/2024, 9:09 PMChris Fillmore
01/26/2024, 1:20 AMStefan Oltmann
01/26/2024, 1:25 AMStefan Oltmann
01/26/2024, 1:27 AMStefan Oltmann
01/26/2024, 1:30 AMval extension: de.stefan_oltmann.VersioningExtension =
project.rootProject.extensions.findByName("gitVersioning")
as de.stefan_oltmann.VersioningExtension
val commitTime: Int = extension.commitTime
android {
[... snip ...]
defaultConfig {
applicationId = "com.ashampoo.photos"
minSdk = Versions.androidMinSdk
targetSdk = Versions.androidTargetSdk
val fiftyYearsInSeconds = 1_600_000_000
// The versionCode can have a max value of 2000000000.
// As a timestamp this is the year 2033 and near future.
// Subtracting 1600000000 gives another 50 years on top.
versionCode = commitTime - fiftyYearsInSeconds
versionName = project.rootProject.version.toString()
}
}
Stefan Oltmann
01/26/2024, 1:34 AM