在摇篮重命名的apk [英] renaming apk in gradle
本文介绍了在摇篮重命名的apk的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从摇篮重命名我的apk。我有以下行内搭
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.
推荐答案
在摇篮插件已经因为你张贴了这个,但得到这个工作与当前的插件(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"))
}
这篇关于在摇篮重命名的apk的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文