android - gradle multiproject include and exclude libraries

android, gradle, multiple-projects

Solution

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é

Problem

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

Original source