Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.hamsterksu:android-appversion-gradle-plugin:'
}
dependencies {
implementation("com.github.hamsterksu:android-appversion-gradle-plugin:")
}
<dependency>
<groupId>com.github.hamsterksu</groupId>
<artifactId>android-appversion-gradle-plugin</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.hamsterksu" % "android-appversion-gradle-plugin" % ""
:dependencies [[com.github.hamsterksu/android-appversion-gradle-plugin ""]]
0.12.+
-> com.github.hamsterksu:android-appversion-gradle-plugin:1.0.+
> 0.14.+
-> com.github.hamsterksu:android-appversion-gradle-plugin:1.2.+
1.0.+
-> com.github.hamsterksu:android-appversion-gradle-plugin:1.2.+
Do you want to use package name, app version name and version code in file name?
Just use the following fileNameFormat
: $appPkg.$versionName($versionCode)
Result - com.yourdomain.app.1.0.0.1(1).apk
Why do you need to use brackets {}
in some cases?
fileNameFormat
- is a Groovy string. Be careful to use something like $appPkg.v_$versionName
. Groovy will try to find the "v_"
property in the String object. And you will get Error: > No such property: v_ for class: java.lang.String
.
In this case you need to use {}
: ${appPkg}.v_$versionName
buildscript {
repositories {
mavenCentral()
}
dependencies{
classpath 'com.github.hamsterksu:android-appversion-gradle-plugin:1.+'
}
}
apply plugin: 'versionPlugin'
versionPlugin{
buildTypesMatcher = 'release'
supportBuildNumber = true
buildNumberPrefix = 'b'
fileNameFormat = '$appPkg-v_$versionName-c_$versionCode'
}
regexp
value. the most useful case: if you want to apply changes for one build type use buildTypesMatcher = 'release'
if for both buildTypesMatcher = 'release|debug'
. Sure you can use any regexp value.true
if you want to add build number
to appVersion
. versions.properties file
will be generated in root project. you can add it to version control ignore list if you use CI or you are alone devloper in the team.string
value, prefix before build number. example: 1.0.0.b1
groovy template string
. you can specify your own format of APK file name. Available variables in the formatted string:
application id
dateFormat
properytimeFormat
properycustomNameMapping
$customName
. it's groovy map
for variantName
-> text
Example:
customNameMapping = [
'debug':'MySuperApp',
'releae':'MySuperApp'
]
customNameMapping = [
'flavourDebug':'MySuperApp',
'flavourRelease':'MySuperApp'
]
If you turn on supportBuildNumber
plugin will generate versions.properties
file in root project. it store current build number for each flavour. You can add it to version control ignore list if you use CI or you are alone devloper in the team.
versionPlugin{
buildTypesMatcher = 'release|debug'
supportBuildNumber = true
buildNumberPrefix = 'b'
fileNameFormat = '$customName-$versionName($versionCode)-$buildType'
customNameMapping = [
'debug':'mysuperapp',
'release':'mysuperapp'
]
}
versionPlugin{
buildTypesMatcher = 'release'
supportBuildNumber = true
fileNameFormat = '$appPkg-$versionName($versionCode)'
}
versionPlugin{
buildTypesMatcher = 'release'
supportBuildNumber = false
fileNameFormat = '$projectName-$flavorName-$versionName($versionCode)-$date-$time'
dateFormat = 'dd-MM-yyyy'
timeFormat = 'HH:mm'
}