I would like to split an Android library project into modules. The intended project structure is:
├─ androidLibraryModule
│
├─ kotlinLibraryModuleA
│
└─ kotlinLibraryModuleB
Where androidLibraryModule
depends on kotlinLibraryModuleA
and kotlinLibraryModuleB
:
dependencies {
implementation project(":kotlinLibraryModuleA")
implementation project(":kotlinLibraryModuleB")
}
The only thing I'll publish is the .aar
which is the result of building androidLibraryModule
and I would like it to include the code from kotlinLibraryModuleA
and kotlinLibraryModuleA
.
The only way I've found so far to achieve this goal is by copying the .jar
files of kotlinLibraryModuleA
and kotlinLibraryModuleB
into the libs
folder of androidLibraryModule
this way:
task copyJar(type: Copy) {
from jar
into "${project(":androidLibraryModule").projectDir.absolutePath}/libs"
}
jar.finalizedBy(copyJar)
This solution works but feels a bit like a hack. Is this the only solution or is there a better way to achieve this result?
EDIT: if androidLibraryModule
was an Android application module, this would just work without the need for a copy task.
The thing is, the
aar
by default only contains code and resources from its module. When you create an app, the library module will pass on it's dependencies to the app, so all classes are included in the final apk.If you want to publish just a library as an
aar
, you have 2 options:pom.xml
, there is eg. this answer: Android library dependencies missing from POM with Gradle