在gradle中重命名apk [英] renaming apk in gradle
本文介绍了在gradle中重命名apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从 gradle 重命名我的 apk.我在 build
I wish to rename my apk from gradle. I have the following lines inside build
applicationVariants.all { variant ->
def file = variant.outputFile
def filename = file.name.replace("SomeXXX", "SomeYYY")
variant.outputFile = new File(file.parent, filename)
}
这成功地重命名了 apk,但没有重命名未对齐的 apk.请有人对此有所了解.
This successfully renames the apks but not the unaligned apks. Please someone throw some light on this.
推荐答案
自从您发布此内容后,gradle 插件已经更新,但是要使其与当前插件 (v1.0.0) 一起使用,您可以使用以下内容:-
The gradle plugin has moved on since you posted this, however to get this working on with the current plugin (v1.0.0), you can use the following:-
variant.outputs.each { output ->
def alignedOutputFile = output.outputFile
def unalignedOutputFile = output.packageApplication.outputFile
// Customise APK filenames (to include build version)
if (variant.buildType.zipAlignEnabled) {
// normal APK
output.outputFile = new File(alignedOutputFile.parent, alignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
}
// 'unaligned' APK
output.packageApplication.outputFile = new File(unalignedOutputFile.parent, unalignedOutputFile.name.replace(".apk", "-" + defaultConfig.versionName + "-" + defaultConfig.versionCode + ".apk"))
}
这篇关于在gradle中重命名apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文