Home

Awesome

android-appversion-gradle-plugin

Android Arsenal

  1. Easy way to add build number to your application version
  2. Easy way to change APK name and add extra data to it.

Supported version of gradle-android-plugin

Сontents

  1. How to use
  2. Add plugin to dependencies
  3. Apply plugin
  4. Configure plugin
  5. Available options
  6. Typical usecases
  7. Use brackets in some cases
  8. What is versions.properties file?
  9. Configuration examples

Typical usecases

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

Use brackets in some cases

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

How to use

Add plugin to dependencies

buildscript {
    repositories {
		mavenCentral()
	}

	dependencies{
		classpath 'com.github.hamsterksu:android-appversion-gradle-plugin:1.+'
	}
}

Apply plugin

apply plugin: 'versionPlugin'

Configure plugin

versionPlugin{
	buildTypesMatcher = 'release'

	supportBuildNumber = true
	buildNumberPrefix = 'b'
	
	fileNameFormat = '$appPkg-v_$versionName-c_$versionCode'
}

Available options:##

Example:

customNameMapping = [
    'debug':'MySuperApp',
    'releae':'MySuperApp'
]
customNameMapping = [
    'flavourDebug':'MySuperApp',
    'flavourRelease':'MySuperApp'
]

What is versions.properties file?

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.

Config examples

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'
}