This plugin allows you to automatically generate your Android versionName and versionCode using Git. It also appends the version and variant names to your APK/AAB and obfuscation mapping artifacts.
The plugin is available from the GradlePluginPortal.
Kotlin
// app build.gradle.kts
plugins {
id("de.nanogiants.android-versioning") version "2.4.0"
}
Groovy
// app build.gradle
plugins {
id 'de.nanogiants.android-versioning' version '2.4.0'
}
or via the
Kotlin
// top-level build.gradle.kts
buildscript {
dependencies {
classpath("de.nanogiants:android-versioning:2.4.0")
}
}
// app build.gradle.kts
apply(plugin = "de.nanogiants.android-versioning")
Groovy
// top-level build.gradle
buildscript {
dependencies {
classpath 'de.nanogiants:android-versioning:2.4.0'
}
}
// app build.gradle
apply plugin: 'de.nanogiants.android-versioning'
Kotlin
android {
defaultConfig {
versionCode = versioning.getVersionCode()
versionName = versioning.getVersionName()
}
}
Groovy
android {
defaultConfig {
versionCode versioning.getVersionCode()
versionName versioning.getVersionName()
}
}
versioning.getVersionCode()
returns the current Git commit countversioning.getVersionName()
returns the latest Git tag
versioning.getVersionName(checkBranch: Boolean)
ifcheckBranch
is set to true the plugin will check if the current branch isrelease/x.x.x
orhotfix/x.x.x
and use the branch name instead the latest tag.
The plugin will automatically rename APK, AAB and Mapping.txt files for all assemble and bundle tasks. This will also work if you do not use the versioning extension in the defaultConfig. You can still use the default archivesBaseName
property.
Build Variant productionStoreRelease
Kotlin
android {
defaultConfig {
setProperty("archivesBaseName", "myAppName")
}
}
Groovy
android {
defaultConfig {
archivesBaseName = "myAppName"
}
}
Artifacts:
myAppName-production-store-3.9.0-3272-release.apk
myAppName-production-store-3.9.0-3272-release.aab
myAppName-production-store-3.9.0-3272-release-mapping.txt
Because Android Studio does not know about the AAB renaming, the locate
or analyze
links in the event log and notifications will only work for APK files by default. You can set keepOriginalArtifacts
to keep the original files. The plugin also prints the file URI for renamed artifacts.
excludeBuildTypes
: comma separated list of buildTypes (e.g. debug) to be excluded from the artifact namingkeepOriginalBundleFile
: copy ABB files instead of renaming them (default false)keepOriginalMappingFile
: copy mapping files instead of renaming them (default true to avoid caching issues)
// app build.gradle
versioning {
excludeBuildTypes = "debug" // default: null
keepOriginalBundleFile = true // default: false
keepOriginalMappingFile = false // default: true
}
Copyright (C) 2020 NanoGiants GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.