標籤:android gradle 渠道 指令碼
在使用gradle 進行多渠道打包的過程中參考了博文:http://blog.csdn.net/qihigh/article/details/17922345 (在此先感謝一下)
然而在使用的過程中使用gradle assembleRelease -Pmc 並不能得到我想要的所有的包,究其原因是:作者使用了buildType來作為渠道的定義類型,這個不能滿足我的需求。而在我的理解,多渠道應當是flavor,因此自己重新寫了一下flavor的指令碼
def falvors = getMyFlavorsFromFileSystem(); productFlavors{ prod { } dev{ } _4T{} falvors.each{name,config-> "$name"{ sourceSets["$name"].res.srcDirs = [config.rrrr] } } }
這樣在在使用assembleRelease -Pmc 時就能夠按照預期的打包產生apk了
附上相關的代碼:
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}
參考文檔:
Android自動構建多平台的包
dynamically-generating-product-flavors
還有這個
Android 使用Gradle動態產生多渠道的APK