我创建了一个具有依赖项的库,例如dagger retrofit rxjava等,当处于模块状态时它可以正常工作但是当我将它变为神器并在新项目中编译它时,项目在开始时崩溃... < / p>
这是堆栈:
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]]
这是我的库依赖项:
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'
}
我的主要猜测是,依赖关系不会与aar文件或其他东西一起使用,有没有办法解决这个问题?在库中使用依赖项的最佳实践是什么?
非常感谢。答案 0 :(得分:3)
我遇到了同样的崩溃,并通过将Dagger库添加到主项目build.gradle中来解决了该问题:
dependencies {
implementation(name:'libraryUsingDagger', ext:'aar')
implementation 'com.google.dagger:dagger:2.21'
annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
}
答案 1 :(得分:0)
将android gradle插件版本升级到3.4.2
后,我遇到了同样的问题。这些选项之一可以帮助您:
3.3.2
android.enableR8=false
行添加到gradle.properties