android figure in front of macbook pro

How to Change APK File Name in Android

Today, I want to share with you some valuable file naming scripts for gradle to change your artifact output file names.

Gradle is a build system which lets you to produce both android archives(.aar) and android packages(.apk) easily.

In android studio the gradle build settings will produce a very boring standart artifact name for you like output files by default.

android gradle artifact apk
Default gradle output filename for apk. {appname}-{flavorname}-{variantname}.apk

To change this default file naming for your artifacts you can use the below scripts:

//apply plugin: '' //uncomment this line for android libraries
//apply plugin: '' //uncomment this line for android applications
def renameArtifact(variant, defaultConfig) {
variant.outputs.each { output ->
def formattedDate = new Date().format('yyyyMMddHHmmss')
def fullName =
def projectName = fullName.substring(0, fullName.indexOf('-'))
output.outputFile = new File(
(String) output.outputFile.parent,
(String), "${projectName}-${defaultConfig.versionName}-${formattedDate}"))
android {
compileSdkVersion 23
buildToolsVersion '23.0.2'
//include this line for your android libraries
//libraryVariants.all { variant -> renameArtifact(variant, defaultConfig) }
//include this line for your android applications
//applicationVariants.all { variant -> renameArtifact(variant, defaultConfig) }
defaultConfig {
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), ''
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
//include your dependencies

view raw


hosted with ❤ by GitHub

For your android library project you have to uncomment line 21.

For your android applications you have to uncomment line 21.

After making these changes, the output will be like that:

android artifact apk
The artifact name is changed after modifying the build.gradle file.

As you can see, the artifact output file name contains appname, current version, timestamp, flavor name, variant name.

If you have any questions, please ask in the comments below.

Thank you.

Related posts





One response to “How to Change APK File Name in Android”

  1. TechToDown Avatar

    Thank you for sharing this helpful guide on changing the APK file name in Android using Gradle. It’s a great way to customize the artifact naming for Android applications and libraries. The step-by-step instructions and explanations are clear and easy to follow.

Leave a Reply

Your email address will not be published. Required fields are marked *