android - gradle multiproject include and exclude libraries

こ雲淡風輕ζ 提交于 2020-01-01 14:49:45

问题


I am trying to build an Android project with Gradle.

It has following structure:

ProjectA----- MainProject,   
LibA     ---- Library project,   
LibB     ---- Library project,   
LibC     ---- Library project,   
LibD     ---- Library project,  
etc...

Based on situtation, I need to include the libraries, sometimes need to include all libraries, 1 library, 2 or 3 etc. based on flavors. In settings file I have included all projects.

Does anybody know how to include/exclude libraries based on flavors?

I have tried on dependency block, there I am getting error.
Following is the sample code

dependencies {
if (task.name.matches('compileFlovor1'){
  exclude module: 'LibD'
   }
}

Error is: Could not find method exclude() for arguments [{module=LibD}].

Please guide me resolving this issue


回答1:


do add flavour specific dependencies you must configure the according configuration. let's say you have to flavours "free" and "payed"

android {
    productFlavors {
        free
        paid
    }
}

then you can set flavour specific dependencies in the dependency block in the following way:

dependencies {
    compile project(':library1')  //library1 used in free and paid flavour
    freeCompile project(':library2')
    paidCompile project(':library3')    
    paidCompile project(':library4')    
    paidCompile project(':library5')     
}

hope that helped,

cheers, René



来源:https://stackoverflow.com/questions/16209874/android-gradle-multiproject-include-and-exclude-libraries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!