我试图基于git分支命名应用程序的APK文件,该分支通过使用jenkins传递参数来工作。但是,我最终得到了两个APK,这是不可取的,因为我执行的一项Gradle任务将APK上传到了分布式列表中。重命名此APK的全部目的是让接收它的人确切知道他们所看到的分支。
buildTypes {
...
feature {
signingConfig signingConfigs.debug
applicationVariants.all { variant ->
appendVersionNameVersionCode(variant, defaultConfig)
}
}
...
}
...
def appendVersionNameVersionCode(variant, defaultConfig) {
//check if staging variant
if(variant.name == android.buildTypes.feature.name){
def branch = hasProperty('branch') ? branch.replaceAll('origin/', '') : "UNKNOWN"
def file = variant.packageApplication.outputFile
def fileName = "myapp-FEATURE-" + branch + ".apk"
variant.packageApplication.outputFile = new File(file.parent, fileName)
}
}
然后,调用gradle命令:
gradle assembleFeature --project-dir=/Path/To/myapp/ -Pbranch=origin/development
从中生成的两个文件是:
不需要文件1,我最终希望重命名该文件,而不是生成一个新文件,即文件2。
有什么想法吗?
最佳答案
事实证明,gradle总是打包2个APK。一种是对齐的,一种不是对齐的。
为了重命名对齐的apk文件,我必须添加以下内容:
if (variant.zipAlign) {
newName = "myapp-FEATURE-" + branch + "-ALIGNED.apk"
variant.outputFile = new File(file.parentFile, newName);
}
关于android - 重命名gradle apk输出文件,但有2个apk,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26026657/