Android uses Gradle to dynamically generate multi-channel APK and gradleapk
In the process of using gradle for multi-channel packaging reference blog: http://blog.csdn.net/qihigh/article/details/17922345 (here first thank you)
However, when using gradle assumerelease-Pmc, I cannot get all the packages I want. The reason is:The author uses buildType as the Channel Definition type.This cannot meet my needs.In my understanding, multiple channels should be flavor.So I re-wrote the flavor script.
def falvors = getMyFlavorsFromFileSystem(); productFlavors{ prod { } dev{ } _4T{} falvors.each{name,config-> "$name"{ sourceSets["$name"].res.srcDirs = [config.rrrr] } } }
In this way, the apk can be generated according to the expected package when using assumerelease-Pmc.
Add the relevant code:
def getMyFlavorsFromFileSystem(){ flavors = [:] if (project.hasProperty('mc')){ println '------setup flavors ---------------' def path = './build-type/type.txt' def prefix = '_' file(path).eachLine{ line -> println line def f = file("./build-type/$line") if (!f.exists()) { f.mkdir() } def resPath = file("./build-type/$line/res-" + prefix+line) if (!resPath.exists()) { resPath.mkdir() } copyRes(resPath.absolutePath,line) flavors.put(prefix+line,[ rrrr : resPath ]) } } return flavors}
Reference:
Android automatically builds multi-platform packages
Dynamically-generating-product-flavors
And this