diff --git a/app/build.gradle b/app/build.gradle index 68a804e6..394e8e37 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,6 +34,12 @@ tasks.register('calculateDictionarySizes') { } } +tasks.register('updateManifest') { + doLast { + updateManifestVersion(getVersionCode()) + } +} + clean { delete LANGUAGES_OUTPUT_DIR } @@ -86,12 +92,14 @@ android { dependsOn(validateLanguages, copyLanguages, calculateDictionarySizes) } - // generateDebugLintReportModel ["lintAnalyzeDebug", "generateDebugLintReportModel", "lintVitalAnalyzeRelease", "generateReleaseLintVitalReportModel"].each { taskName -> tasks.named(taskName)?.configure { dependsOn(validateLanguages, copyLanguages, calculateDictionarySizes) } } + + assembleDebug.finalizedBy(updateManifest) + assembleRelease.finalizedBy(updateManifest) } } diff --git a/app/version-tools.gradle b/app/version-tools.gradle index 8deaf023..c2bbfc44 100644 --- a/app/version-tools.gradle +++ b/app/version-tools.gradle @@ -60,3 +60,12 @@ ext.getDebugVersion = { -> 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) +}