Is it possible to specify the filename of the generated *.apk through gradle? So that I automatically could get MyApp-1.0.0.apk
instead of the default app-release.apk
.
Asked
Active
Viewed 3,834 times
4
2 Answers
4
You can do this by adding the following line to your build.gradle
file inside the android{...}
part:
android.applicationVariants.all { variant ->
variant.outputFile = file("$project.buildDir/${defaultConfig.versionName}-${defaultConfig.versionCode}.apk")
}
Notes:
- Everything inside the
file(...)
is arbitrary, of course - This code will output the *.apk to your
project/module/build
directory, no matter what path you've specified when Building the Signed APK. - The output-file will take the Name and Version-Code from your
build.gradle
file. - Android Studio may complain that it "cannot resolve symbol applicationVariants/defaultConfig" - ignore it. ;)

reVerse
- 35,075
- 22
- 89
- 84
1
Got it working! Used this answer
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(
output.outputFile.parent,
output.outputFile.name.replace(".apk", "-${variant.versionName}.apk"))
}
}
}

Community
- 1
- 1

Mike Rapadas
- 4,613
- 2
- 28
- 21