TL; DR: When using a library in an AndroidProject, why must I include all library's dependencies ?
Long story:
Let's say I have a simple Android Library Project that contains a module named LibModule.
Let's say this library LibModule depends on another library, defined in LibModule/build.gradle like this :
dependencies {
// example :
compile 'org.igniterealtime.smack:smack-android:4.1.0-beta1'
}
I'm able to generate the library of this module, LibModule.aar.
Now I want to use classes from the library LibModule in a new Android Project called MyApp.
I copy this LibModule.aar into MyApp/app/libs/.
Then in MyApp/app/build.gradle, I add this :
dependencies {
compile(name:'LibModule', ext:'aar')
}
I'm now able to uses classes from LibModule in MyApp's Activities. It compiles great. No errors.
When I launch MyApp/app, at runtime, I get this stacktrace when using LibModule's classes :
java.lang.NoClassDefFoundError: Failed resolution of: Lorg/jivesoftware/smack/tcp/XMPPTCPConnectionConfiguration;
(...Stacktrace...)
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration" on path: DexPathList[[zip file "/data/app/MyApp/app/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
(...)
Suppressed: java.lang.ClassNotFoundException: org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration
(...)
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
XMPPTCPConnectionConfiguration comes from org.igniterealtime.smack:smack-android:4.1.0-beta1, a dependency of LibModule.
It's really weird !
I found a solution to this : adding org.igniterealtime.smack:smack-android:4.1.0-beta1 dependency in MyApp/app's build.gradle, but I guess this is not the right way to manage this error.
I thought org.igniterealtime.smack:smack-android:4.1.0-beta1 was "packed" in LibModule.aar, but it seems not...
I would like to know if there is something I'm doing badly, because this workaround looks realy dirty to me!
EDIT: Duplicate of this and this , but none of the answer resolved the problem....