问题描述
我有一个基于Android的摇篮项目,我想改变mapping.txt文件名后,这对我的构建产生。怎样才能做到呢?
I have android project based on gradle and I want to change mapping.txt file name after it's generated for my build. How can it be done?
UPD
如何能在build.gradle做什么?既然我有机会在那里我的口味和其他僵硬,我想创建映射文件名的基础上的味道/构建变种版本。
How it can be done in build.gradle? Since I have access there to my flavors and other stiff, I would like to create mapping file name based on flavor/build variant version.
推荐答案
许多感谢名单,以谢尔盖·Pechenizkyi 谁帮我发现这个很好的解决方案。
Many thanx to Sergii Pechenizkyi who helped me to found this good solution.
要实现的ProGuard的映射文件复制为每种口味,我们可以创建根的任务 copyProguardMappingTask
和动态任务数为每味
To implement copying of proguard mapping files for each flavor we can create "root" task copyProguardMappingTask
and number of dynamic tasks for each flavor
def copyProguardMappingTask = project.tasks.create("copyProguardMapping")
applicationVariants.all { variant ->
variant.outputs.each { output ->
...
if (variant.getBuildType().isMinifyEnabled()) {
def copyProguardMappingVariantTask = project.tasks.create("copyProguardMapping${variant.name.capitalize()}", Copy)
def fromPath = variant.mappingFile;
def intoPath = output.outputFile.parent;
copyProguardMappingVariantTask.from(fromPath)
copyProguardMappingVariantTask.into(intoPath)
copyProguardMappingVariantTask.rename('mapping.txt', "mapping-${variant.name}.txt")
copyProguardMappingVariantTask.mustRunAfter variant.assemble
copyProguardMappingTask.dependsOn copyProguardMappingVariantTask
}
}
}
之后,我们应该运行组装我们的项目后,这个任务。我用詹金斯和我的任务选项看起来像
afterwards we should run this task after assembling our project. I use jenkins and my tasks option looks like
gradle clean assembleProjectName copyProguardMapping
它的工作原理就像一个魅力。
It works like a charm.
这篇关于如何改变ProGuard的映射文件名在摇篮的Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!