android:visibility="gone” tools:visibility="visible”
import java.util.regex.Pattern android { buildTypes { debug { applicationIdSuffix '.debug' debuggable true runProguard false jniDebugBuild false } release { signingConfig signingConfigs.release applicationVariants. { variant -> def file = variant.outputFile; def newName = file.name.replace("release.apk", "release_v" + getVersionCode() + "_" + getDate() + ".apk"); variant.outputFile = new File(file.parent, newName) } runProguard true proguardFile file("proguard.pro") debuggable false jniDebugBuild false } } } def getDate() { def date = new Date() def formattedDate = date.format('yyyy-MM-dd') return formattedDate } def getVersionCode() { println "getVersionCode" def manifestFile = file("AndroidManifest.xml") def pattern = Pattern.compile("versionCode=\"(\\d+)\"") def manifestText = manifestFile.getText() def matcher = pattern.matcher(manifestText) matcher.find() def version = ++Integer.parseInt(matcher.group(1)) println sprintf("Returning version %d", version) return version } task incrementVersionCode << { println(":incrementVersionCode - Incrementing Version Code...") def manifestFile = file("src/main/AndroidManifest.xml") def patternVersionCode = Pattern.compile("versionCode=\"(\\d+)\"") def manifestText = manifestFile.getText() def matcherVersionCode = patternVersionCode.matcher(manifestText) matcherVersionCode.find() def mVersionCode = Integer.parseInt(matcherVersionCode.group(1)) def mNextVersionCode = mVersionCode + 1 def manifestContent = matcherVersionCode.replaceAll("versionCode=\"" + mNextVersionCode + "\"") println(":incrementVersionCode - current versionCode=" + mVersionCode); println(":incrementVersionCode - next versionCode=" + mNextVersionCode); manifestFile.write(manifestContent) } task incrementVersionName << { println(":incrementVersionName - Incrementing Version Name...") def manifestFile = file("src/main/AndroidManifest.xml") def patternVersionNumber = Pattern.compile("versionName=\"(\\d+)\\.(\\d+)\"") def manifestText = manifestFile.getText() def matcherVersionNumber = patternVersionNumber.matcher(manifestText) matcherVersionNumber.find() def majorVersion = Integer.parseInt(matcherVersionNumber.group(1)) def minorVersion = Integer.parseInt(matcherVersionNumber.group(2)) def mVersionName = majorVersion + "." + minorVersion def mNextVersionName = majorVersion + "." + (minorVersion + 1) def manifestContent = matcherVersionNumber.replaceAll("versionName=\"" + mNextVersionName + "\"") println(":incrementVersionName - current versionName=" + mVersionName); println(":incrementVersionName - new versionName=" + mNextVersionName); manifestFile.write(manifestContent) } task release << { println(":release - Build and Version Increment") } task debug << { println(":debug - Build") } incrementVersionName.mustRunAfter build incrementVersionCode.mustRunAfter build debug.dependsOn assembleDebug release.dependsOn assembleRelease release.dependsOn incrementVersionCode release.dependsOn incrementVersionName
productFlavors { free { packageName "by.yegorov.communal" buildConfigField "boolean", "PAID", "false" } paid { packageName "yo.mobile.meters" buildConfigField "boolean", "PAID", "true" } }
productFlavors { debugServer { buildConfigField "String", "SERVER_PATH", "\"http://test.api.ru\"" } releaseServer { buildConfigField "String", "SERVER_PATH", "\"http://api.ru\"" } }
Source: https://habr.com/ru/post/239199/
All Articles