Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android library multiple modules

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 and E)
Those modules sometimes require another library and sometimes have things to add in the resulting manifest.

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!

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

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
}

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?

Is there a simpler way to do such a build?

like image 755
SeikoTheWiz Avatar asked Dec 10 '25 05:12

SeikoTheWiz


1 Answers

Create multiple standalone android library modules and use custom gradle scripts to pull and use the necessary modules

like image 176
Jonathan Avatar answered Dec 11 '25 19:12

Jonathan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!