Android 使用Gradle動態產生多渠道的APK

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.