I am working on an android project.I want to build this project by gradle. And I need to generate 20 apk files according to the different market channels.The difference of the files is that in the manifest file ,I need to replace the string"UMENG_VALUE"with each channel name. My current way is to use product flavor like this:
productFlavors {
develop{}
official{}
ika{}
}
android.applicationVariants.all{variant ->
variant.processManifest.doLast{
def manifestFile = "${buildDir}/intermediates/manifests/${variant.dirName}/AndroidManifest.xml"
new File(manifestFile).write(new File(manifestFile).getText('UTF-8').replaceAll("@string/channel_id", "${variant.productFlavors[0].name}"), 'UTF-8')
variant.processResources.manifestFile = file("${buildDir}/intermediates/manifests/${variant.dirName}/AndroidManifest.xml")
}
}
But the problem of this method is that gradle will execute every task according to each flavor right? But in my opinion , most of the steps are exactly the same. So is there a better way for gradle to just compile and dex for only one time and just change the String in manifest file?