I am trying to create an android library, moduleD, that depends on another library module, which in turn depends on two library modules. Everything seemingly builds fine, but I get a ClassNotFoundException
when I try to use the library in an application.
Setup
MyLibrary/
+-- moduleA
+-- src/main/java/
+-- com/example/a
+-- moduleB
+-- src/main/java/
+-- com/example/b
+-- moduleC
+-- src/main/java/
+-- com/example/b
+-- com/example/c
`-- MyMissingClass.java <-- MISSING
+-- moduleD
+-- src/main/java/
+-- com/example/b
build.gradle (Module C)
dependencies {
compile project(':moduleA')
compile project(':moduleB')
}
build.gradle (Module D)
dependencies {
compile project(':moduleC')
}
In my application I call ModuleD which calls Module
For completeness's sake, I'm referencing the resulting aars locally, but I don't think that's the issue. Unzipping classes.jar in moduleD, I can see moduleD's class files, but not MyMissingClass.
build.gradle (in separate application project)
repositories {
...
flatDir {
dirs 'libs'
}
}
dependencies {
compile(name:'moduleB', ext:'aar')
}
non-Solution
Transitive dependency[1][2]
[1] : How to include dependencies in android library gradle project? [2] : How do I ship an Android Library (aar) with remote dependencies (gradle)?
build.gradle (application)
dependencies {
compile(name:'moduleD', ext:'aar') {
transitive true
}
}
This may work for external dependencies (e.g. available through maven, either central or local) and it makes sense to avoid bundling external dependencies, which could otherwise be upgraded/downgraded independently to avoid conflicts or get bugfixes. However, modules A-C are internal to the project and for now only used in this one library.
Question
Is it possible to create an aar (or jar) for moduleD that contains all the classes and can actually be used in an application given that the library project is broken into separate modules?