Ответ 1
EDIT: для современных версий инструментов Gradle используйте вариацию @ptx (используйте output.outputFile
вместо variant.outputFile
:
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
output.outputFile = new File(output.outputFile.parentFile,
output.outputFile.name.replace(".apk", "${variant.versionName}.apk"));
}
}
}
Как и в случае с Gradle плагином для инструментов версии 0.14, вы должны использовать следующее вместо этого, чтобы правильно поддерживать несколько выходных файлов (например, APK Splits):
android {
applicationVariants.all { variant ->
variant.outputs.each { output ->
variant.outputFile = new File(variant.outputFile.parentFile,
variant.outputFile.name.replace(".apk", "${variant.versionName}.apk"));
}
}
}
Для более старых версий:
Да, мы делаем это в нашем приложении. Просто добавьте следующее в свой тег android в build.gradle:
android {
applicationVariants.all { variant ->
def oldFile = variant.outputFile
def newPath = oldFile.name.replace(".apk", "${variant.versionName}.apk")
variant.outputFile = new File(oldFile.parentFile, newPath)
}
}