简体   繁体   English

启动时,android库发布崩溃

[英]android library release crash on start

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... 我创建了一个具有依赖关系的库,例如dagger retrofit rxjava等,当它处于模块状态时工作正常但是当我将它变为神器并在新项目中编译它时,项目在开始时崩溃...

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 ? 我的主要猜测是依赖关系不适用于aar文件或其他东西,有没有办法解决这个问题? 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: 我得到了相同的崩溃并通过将Dagger库添加到主项目build.gradle来解决它:

dependencies {
    implementation(name:'libraryUsingDagger', ext:'aar')

    implementation 'com.google.dagger:dagger:2.21'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.21'
}

I had the same issue after upgrading android gradle plugin version to 3.4.2 . 将android gradle插件版本升级到3.4.2后,我遇到了同样的问题。 One of these options can help: 其中一个选项可以帮助:

  1. Downgrade android gradle plugin version to 3.3.2 将android gradle插件版本降级到3.3.2
  2. Add android.enableR8=false line to gradle.properties android.enableR8=false行添加到gradle.properties

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM