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') { tasks.register('updateManifest') {
doLast { doLast {
updateManifestVersion(getVersionCode()) updateManifestVersion(getVersionCode(), getVersionName())
} }
} }

View file

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