diff --git a/bin/templates/project/build.gradle b/bin/templates/project/build.gradle index b62a258f..ca86c280 100644 --- a/bin/templates/project/build.gradle +++ b/bin/templates/project/build.gradle @@ -56,7 +56,7 @@ android { } defaultConfig { - versionCode Integer.parseInt(System.env.ANDROID_VERSION_CODE ?: ("" + getVersionCodeFromManifest() + "0")) + versionCode Integer.parseInt(System.env.ANDROID_VERSION_CODE ?: ("" + getIntFromManifest("versionCode") + "0")) } compileSdkVersion cordova.cordovaSdkVersion @@ -82,6 +82,8 @@ android { } } } + } else if (getIntFromManifest("minSdkVersion") >= 20) { + defaultConfig.versionCode += 9 } compileOptions { @@ -163,9 +165,9 @@ gradle.taskGraph.whenReady { taskGraph -> } } -def getVersionCodeFromManifest() { +def getIntFromManifest(name) { def manifestFile = file(android.sourceSets.main.manifest.srcFile) - def pattern = Pattern.compile("versionCode=\"(\\d+)\"") + def pattern = Pattern.compile(name + "=\"(\\d+)\"") def matcher = pattern.matcher(manifestFile.getText()) matcher.find() return Integer.parseInt(matcher.group(1))