Home > database >  Building an Android Library module that depends on two other modules including the modules classes a
Building an Android Library module that depends on two other modules including the modules classes a

Time:02-17

I need help solving this issue. My project has three modules, which I'll call modules A, B and C. All of them are Android Library modules.

C is the end product. I want to export it as an AAR that includes all the classes and resources from A and B.

I noticed that merely adding:

implementation project(':libA')
implementation project(':libB')

wont add A and B to C and I would have to distribute them separately, which is not what I want (although I could do that if there is no other way).

I also noticed that if I build A and B, manually copy the resulting AAR to a lib folder inside C and add the dependency as

implementation fileTree(include: ["*.aar"], dir: "libs")

then it DOES include A and B in the final result. But I don't want to have to manually do that every time, so instead what I want is to create a gradle task that will do this for me.

After several tries, no luck. I haven't been able to create this. So far what I tried is creating a custom gradle configuration (let's call it aarDependency) and declaring the dependency as

aarDependency project(':libA')
aarDependency project(':libB')

then I wrote my task as

task copyAARDependencies(type: Copy) {
    dependsOn(":libA:assembleRelease")
    dependsOn(":libB:assembleRelease")

    from configurations.aarDependency.artifacts.files
    into("libs")
}

but alas, no files are copied.

Has anyone any solution for that? It doesn't need to be a gradle script if there is another solution.

Thanks in advance.

CodePudding user response:

You are trying to achieve a so-called "fat-aar", there's a Gradle plugin available for that https://github.com/kezong/fat-aar-android

  • Related