Very modulable android library project and gradle configuration/flavors

I am building a library on android, which is composed of a big core and several modules (let’s name them A, B, C, D, E and F) Those modules sometimes require another library and sometimes have things to add in the resulting manifest. We can even have A and B depending on a different version of the same library (so not compatible)

I would like to be able to build my core with any number of modules.

I started by creating flavors which are really useful but are a bit limited in my case.

If I wanted to create a flavor for each cases it would mean creating A LOT of them! But I’m guessing there is a simpler way to do what I would like to do.

Is there a simpler way to do such a build?

thanks!

apply plugin: 'com.android.library'
  android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"
      flavorDimensions "libA", "libB", "libC", "libD", "libF"
    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 21
        versionCode 11
        versionName "3.1.0"
    }
      productFlavors {
        A {
          flavorDimension "libA"
        }
          B {
          flavorDimension "libB"
        }
          C {
          flavorDimension "libC"
        }
          D {
          flavorDimension "libD"
        }
          E {
          flavorDimension "libB"
        }
          F {
          flavorDimension "libF"
        }
    }
      sourceSets {
        A {
            java {
                srcDirs = ['src/A']
            }
        }
          B {
            java {
                srcDirs = ['src/B']
            }
        }
          C {
            java {
                srcDirs = ['src/C']
            }
        }
          D {
            java {
                srcDirs = ['src/D']
            }
        }
          E {
            java {
                srcDirs = ['src/E']
            }
        }
          F {
            java {
                srcDirs = ['src/F']
            }
        }
    }
}
  dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.google.android.gms:play-services:6.5.87'
      androidTestCompile 'org.mockito:mockito-core:1.10.19'
    androidTestCompile 'com.google.dexmaker:dexmaker:1.0'
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
      ACompile files('libs/A-2.1.0.jar')
      BCompile files('libs/B-4.1.0.jar')
      CCompile files('libs/C-5.1.0.jar')
      DCompile files('libs/D-1.01.jar')
      // same library as B, but different version
    ECompile files('libs/B-5.2.2.jar')
      // F nothing
}

A gradle file to explain what I would like to do.

What I would like to be able to produce is:

A.aar B.aar C.aar D.aar E.aar F.aar A+B.aar A+C.aar A+D.aar A+E.aar A+F.aar A+B+C.aar A+B+D.aar A+B+F.aar (since B and E are not compatible) A+C+D.aar A+C+E.aar

etc. etc. etc…

When I try with this gradle file, and launch “gradlew assembleRelease” I only obtain: A+B+C+D+F.aar and A+C+D+E+F.aar

What would be modified to obtain the result I’m looking for?