I created a library that has dependencies such as dagger retrofit rxjava etc, when in module state it works fine but when I depoy it to artifactory and compile it in a new project , the project crashes right at the start...
this is the stack :
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.yanivtwina.myapplication, PID: 13057
java.lang.NoClassDefFoundError: Failed resolution of: Ldagger/internal/Preconditions;
at com.galcomm.mobiklib.DaggerNetComponent$Builder.appModule(DaggerNetComponent.java:184)
at com.galcomm.mobiklib.MobikApp.onCreate(MobikApp.java:24)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1119)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5740)
at android.app.ActivityThread.-wrap1(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1656)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6494)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.ClassNotFoundException: Didn't find class "dagger.internal.Preconditions" on path: DexPathList[[zip file "/data/app/com.example.yanivtwina.myapplication-W0HdPexc2tZZOvAVgNzjIg==/base.apk"],nativeLibraryDirectories=[/data/app/com.example.yanivtwina.myapplication-W0HdPexc2tZZOvAVgNzjIg==/lib/arm64, /system/lib64, /vendor/lib64]]
and here are my library dependencies :
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-messaging:11.0.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.dagger:dagger:2.9'
compile 'com.squareup.retrofit2:retrofit:2.+'
compile 'com.squareup.retrofit2:converter-gson:2.+'
compile 'com.squareup.retrofit2:adapter-rxjava:2.+'
compile 'io.reactivex:rxjava:1.0.4'
compile "com.google.android.gms:play-services-gcm:11.0.4"
compile 'io.reactivex:rxandroid:0.24.0'
compile 'com.android.support:design:23.4.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile 'com.android.support:support-v4:23.4.0'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.6.0'
annotationProcessor 'com.google.dagger:dagger-compiler:2.9'
provided 'javax.annotation:jsr250-api:1.0'
compile 'com.evernote:android-job:1.1.8'
}
My main guess is that the dependencies don't go with the aar file or something , is there a way to fix that ? what is the best practice for using dependencies in your library ?
much thanks .
I got the same crash and solved it by adding the Dagger libraries to the main project build.gradle:
dependencies {
implementation(name:'libraryUsingDagger', ext:'aar')
implementation 'com.google.dagger:dagger:2.21'
annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
}