"how to auatomatically update version code in android gradle" Code Answer's
You're definitely familiar with the best coding language Whatever that developers use to develop their projects and they get all their queries like "how to auatomatically update version code in android gradle" answered properly. Developers are finding an appropriate answer about how to auatomatically update version code in android gradle related to the Whatever coding language. By visiting this online portal developers get answers concerning Whatever codes question like how to auatomatically update version code in android gradle. Enter your desired code related query in the search bar and get every piece of information about Whatever code related question on how to auatomatically update version code in android gradle.
how to auatomatically update version code in android gradle
android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
def versionPropsFile = file('version.properties')
def value = 0
Properties versionProps = new Properties()
if (!versionPropsFile.exists()) {
versionProps['VERSION_PATCH'] = "0"
versionProps['VERSION_NUMBER'] = "0"
versionProps['VERSION_BUILD'] = "-1" // I set it to minus one so the first build is 0 which isn't super important.
versionProps.store(versionPropsFile.newWriter(), null)
}
def runTasks = gradle.startParameter.taskNames
if ('assembleRelease' in runTasks) {
value = 1
}
def mVersionName = ""
def mFileName = ""
if (versionPropsFile.canRead()) {
versionProps.load(new FileInputStream(versionPropsFile))
versionProps['VERSION_PATCH'] = (versionProps['VERSION_PATCH'].toInteger() + value).toString()
versionProps['VERSION_NUMBER'] = (versionProps['VERSION_NUMBER'].toInteger() + value).toString()
versionProps['VERSION_BUILD'] = (versionProps['VERSION_BUILD'].toInteger() + 1).toString()
versionProps.store(versionPropsFile.newWriter(), null)
// 1: change major and minor version here
mVersionName = "v1.0.${versionProps['VERSION_PATCH']}"
// 2: change AppName for your app name
mFileName = "AppName-${mVersionName}.apk"
defaultConfig {
minSdkVersion 21
targetSdkVersion 27
applicationId "com.example.appname" // 3: change to your package name
versionCode versionProps['VERSION_NUMBER'].toInteger()
versionName "${mVersionName} Build: ${versionProps['VERSION_BUILD']}"
}
} else {
throw new FileNotFoundException("Could not read version.properties!")
}
if ('assembleRelease' in runTasks) {
applicationVariants.all { variant ->
variant.outputs.all { output ->
if (output.outputFile != null && output.outputFile.name.endsWith('.apk')) {
outputFileName = mFileName
}
}
}
}
task copyApkFiles(type: Copy){
from 'build/outputs/apk/release'
into '../apk'
include mFileName
}
afterEvaluate {
assembleRelease.doLast {
tasks.copyApkFiles.execute()
}
}
signingConfigs {
...
}
buildTypes {
...
}
}
Source: stackoverflow.com
All those coders who are working on the Whatever based application and are stuck on how to auatomatically update version code in android gradle can get a collection of related answers to their query. Programmers need to enter their query on how to auatomatically update version code in android gradle related to Whatever code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about how to auatomatically update version code in android gradle for the programmers working on Whatever code while coding their module. Coders are also allowed to rectify already present answers of how to auatomatically update version code in android gradle while working on the Whatever language code. Developers can add up suggestions if they deem fit any other answer relating to "how to auatomatically update version code in android gradle". Visit this developer's friendly online web community, CodeProZone, and get your queries like how to auatomatically update version code in android gradle resolved professionally and stay updated to the latest Whatever updates.