SoFunction
Updated on 2025-04-09

How to customize and modify packaged apk name on Android

When we package apk, we will generate or, by default, we need to manually modify the name of the apk every time to distinguish the names of each version.
In fact, we can modify the configuration file and automatically modify the apk name every time we package it.

1. Modify the Module configuration file

Add the following information under the Android closure:

android{
    //...
    { variant ->
        {
            def createTime = new Date().format("YYYYMMddHHmm", ("GMT+08:00"))
           def fileName = "${}_${}_${}_${createTime}.apk"
           outputFileName = fileName
        }
    }
    //...
}
  • ${}: The name of the current Module
  • ${}: The current build type, debug or release or custom flavor
  • ${} : Version name. For versionName in defaultConfig, we can also use ${} to represent versionCode in defaultConfig;
  • ${createTime}: Custom packaging time, the time format is: YYYYMMddHHmm.

2. Multi-channel packaging and modify the apk name

Add the following information under the Android closure:

android{
    //...
     { variant ->
         {
            def createTime = new Date().format("YYYYMMddHHmm", ("GMT+08:00"))
            def fileName = "${[0].name}_${}_${}_${createTime}.apk"
            outputFileName = fileName
        }
    }
    //...
}

3. Kotlin DSL configuration custom packaged apk name

First, you need to add the lead package, import and import to get the current time.

Add the following information under the Android closure:

import 
import 
android{
    //...
     {
         {
            if (this is ) {
                val config = 
                val versionName = 
                val formatter = ("yyyyMMddHHmm")
                val createTime = ().format(formatter)
                 = "${}_${}_${versionName}_$"
            }
        }
    }
    //...
}

This is the article about Android custom modification of packaging apk name. For more related content on Android packaging apk name, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!