1
0
Fork 0

AndroidManifest.xml versionName is also automatically updated on build

This commit is contained in:
sspanak 2024-02-24 11:04:50 +02:00 committed by Dimo Karaivanov
parent 2547eda8bd
commit 6f1bb5820a
2 changed files with 10 additions and 8 deletions

View file

@ -38,7 +38,7 @@ tasks.register('writeDictionaryProperties') {
tasks.register('updateManifest') {
doLast {
updateManifestVersion(getVersionCode())
updateManifestVersion(getVersionCode(), getVersionName())
}
}

View file

@ -61,11 +61,13 @@ ext.getReleaseVersion = { ->
return "${generateVersionName()} (${getCurrentGitHash()})"
}
ext.updateManifestVersion = { currentVersion ->
def manifestFile = file("src/main/AndroidManifest.xml")
def pattern = ~"versionCode=\"([^\"]+)\""
def matcher = pattern.matcher(manifestFile.getText())
matcher.find()
def newManifest = matcher.replaceAll("versionCode=\"" + (currentVersion + 1) + "\"")
manifestFile.write(newManifest)
ext.updateManifestVersion = { versionCode, versionName ->
def manifestFile = file("src/main/AndroidManifest.xml")
def newManifest = manifestFile
.getText()
.replaceFirst(~"versionCode=\"([^\"]+)\"", "versionCode=\"" + versionCode + "\"")
.replaceFirst(~"versionName=\"([^\"]+)\"", "versionName=\"" + versionName + "\"")
manifestFile.write(newManifest)
}