Generate app name with version code, name and flavour name – Android

After a build is shared to a team or group of people, sometimes a question arises that what was the version code/name of the build shared, or from which product flavour it was from. Developers can inspect these details using analyse apk option in Android Studio. But, the problem is with other member who do not have Android studio to inspect these details.

In order to resolve this issue, it is better to put these details with APK filename. In this way all the details can be verified just by looking at the filename.

To achieve this we can put this gradle function in application level build.gradle file.

android.applicationVariants.all { variant ->
    def appName
    // if applicationName property is set in
    if (project.hasProperty("applicationName")) {
        appName = applicationName
    } else {
    // if not use the name of the parent project
        appName =
    appName = appName.replaceAll(" ", "_")
    def formattedDate = new Date().format('yyyy-MM-dd_HH:mm:ss')
    variant.outputs.all { output ->
        outputFileName = "${appName}-${output.baseName}-${variant.versionCode}" +
        println("outputFileName: " + outputFileName)

The output of adding this gradle code block will be like this, considering following details

  1. Application name is “App Name”
  2. You have two product flavours setup, i.e. dev and prod.
  3. Application version code is 16
  4. Application version name is 2.7.4 (-dev is setup as versionNameSuffix)