Set Android apk filename in Gradle
Updated in Android GradleBy default the Android gradle plugin creates app-debug.apk, app-release-unsigned.apk and app-release.apk apk files during the build process. Fortunately it’s easy to change the file name to suit your need. You only need to the add the following to the application module build.gradle file (for example app/build.gradle):
android {
...
defaultConfig {
...
setProperty("archivesBaseName", "AppNameHere")
}
...
}
With this change the Gradle build will output AppNameHere-debug.apk, AppNameHere-release-unsigned.apk and AppNameHere-release.apk files.
You can also use variables in the filename. So if you, for example, wish to include the version number in the filename (AppNameHere-1.0-release.apk), you can achieve it with this:
setProperty("archivesBaseName", "AppNameHere-$versionName")
In addition to versionName, you can also use other variables set in the defaultConfig block.
Control the whole filename
If you want to have total control over the filename, that is you want to get rid of the -debug, -release and -unsigned suffixes. Then you just need to add the following to the build.gradle:
android {
...
applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "AppNameHere.apk"
}
}
...
}
This will set the whole filename without any of the suffixes.
If you still want to include variables in the filename, that’s also possible:
outputFileName = "AppNameHere-${defaultConfig.versionName}-${variant.buildType.name}.apk"