Android:失败的解决方案:Ldagger / internal / Preconditions

时间:2017-10-13 07:16:59

标签: android android-studio dagger-2 dagger

我的应用运行良好,但由于我的操作系统Debian的一些问题,我决定重新安装它,我选择安装Ubuntu-16.04而不是最后一个Debian。现在一切都好。

问题是我的android应用程序。重新安装 android-studio 稳定版后,我无法再测试我的应用程序了。

为什么? 因为每次启动应用程序时,都会出现此错误。我不知道它的意思,经过一些互联网研究,我没有得到任何东西。 这是堆栈跟踪

10-13 07:47:10.749 1631-1631/com.gre E/AndroidRuntime: FATAL EXCEPTION: main
                                                      Process: com.gre, PID: 1631
                                                      java.lang.NoClassDefFoundError: Failed resolution of: Ldagger/internal/Preconditions;
                                                          at com.gre.di.components.DaggerApplicationComponent$Builder.applicationModule(DaggerApplicationComponent.java:209)
                                                          at com.gre.GreApplication.onCreate(GreApplication.java:47)
                                                          at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593)
                                                          at android.app.ActivityThread.access$1600(ActivityThread.java:154)
                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
                                                          at android.os.Handler.dispatchMessage(Handler.java:102)
                                                          at android.os.Looper.loop(Looper.java:135)
                                                          at android.app.ActivityThread.main(ActivityThread.java:5294)
                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                          at java.lang.reflect.Method.invoke(Method.java:372)
                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904)
                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699)
                                                       Caused by: java.lang.ClassNotFoundException: Didn't find class "dagger.internal.Preconditions" on path: DexPathList[[zip file "/data/app/com.gre-1/base.apk", zip file "/data/app/com.gre-1/split_lib_dependencies_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_0_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_1_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_2_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_3_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_4_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_5_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_6_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_7_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_8_apk.apk", zip file "/data/app/com.gre-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.gre-1/lib/arm, /vendor/lib, /system/lib]]
                                                          at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
                                                          at com.gre.di.components.DaggerApplicationComponent$Builder.applicationModule(DaggerApplicationComponent.java:209) 
                                                          at com.gre.GreApplication.onCreate(GreApplication.java:47) 
                                                          at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012) 
                                                          at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4593) 
                                                          at android.app.ActivityThread.access$1600(ActivityThread.java:154) 
                                                          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382) 
                                                          at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                          at android.os.Looper.loop(Looper.java:135) 
                                                          at android.app.ActivityThread.main(ActivityThread.java:5294) 
                                                          at java.lang.reflect.Method.invoke(Native Method) 
                                                          at java.lang.reflect.Method.invoke(Method.java:372) 
                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:904) 
                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:699) 
                                                        Suppressed: java.lang.ClassNotFoundException: dagger.internal.Preconditions
                                                          at java.lang.Class.classForName(Native Method)
                                                          at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
                                                          at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
                                                          at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
                                                                ... 14 more
                                                       Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

如何解决呢?

这是我的 build.gradle 文件

    apply plugin: 'com.android.application'
     apply plugin: 'realm-android'
     // apply plugin: 'com.neenbedankt.android-apt'

     android {
         compileSdkVersion 25
         buildToolsVersion '25.0.2' // '23.0.2'

    defaultConfig {
        applicationId "com.gre"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true

    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }

        /*debug {
            applicationIdSuffix ".debug"
        }*/

        /**
         * The 'initWith' property allows you to copy configurations from other build types,
         * so you don't have to configure one from the beginning. You can then configure
         * just the settings you want to change. The following line initializes
         * 'jnidebug' using the debug build type, and changes only the
         * applicationIdSuffix and versionNameSuffix settings.
         */

        jnidebug {

            // This copies the debuggable attribute and debug signing configurations.
            initWith debug

            applicationIdSuffix ".jnidebug"
            jniDebuggable true
        }
    }
    dexOptions {
        // javaMaxHeapSize "2048M"
        javaMaxHeapSize "4g"
    }
    configurations.all {
        // all*.exclude group: 'com.squareup.okhttp3', module: 'okhttp'configurations.all {
        // OkHttp 3.5.0+ includes the websockets API, so we need this to prevent a conflict
        exclude module: 'okhttp-ws'
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile('io.socket:socket.io-client:0.8.1') {
        exclude group: 'org.json', module: 'json'
    }

    /*compile 'com.google.android.gms:play-services-auth:10.0.1'
    compile 'com.google.android.gms:play-services-maps:10.0.1'
    compile 'com.google.android.gms:play-services-appindexing:10.0.1'*/

    // compile 'com.android.support.constraint:constraint-layout:1.0.2'

    // Android
    // Glide

    // Facebook Stetho
    // OkHttp
    // SquareUp
    // Rx
    // Dragger
    // Realm

    // RippleButton
    compile 'com.balysv:material-ripple:1.0.2'
    compile 'com.android.support:appcompat-v7:'
    compile "com.android.support:cardview-v7:${buildTools}"
    compile "com.android.support:recyclerview-v7:${buildTools}"
    compile "com.android.support:design:${buildTools}"
    compile "com.android.support:support-v13:${buildTools}"
    compile "com.android.support:support-v4:${buildTools}"
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.github.bumptech.glide:glide:4.0.0-RC0'
    compile 'com.github.florent37:materialtextfield:1.0.7'
    compile 'uk.co.chrisjenx:calligraphy:2.2.0'
    compile 'com.splitwise:tokenautocomplete:2.0.8@aar'
    compile 'com.github.Plumillon:ChipView:1.2.0'
    compile 'com.github.clans:fab:1.6.4'
    compile 'org.greenrobot:eventbus:3.0.0'
    compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
    compile 'com.google.android.gms:play-services:10.2.6'
    compile 'com.google.android.gms:play-services-location:10.2.6'
    compile 'com.google.android.gms:play-services-maps:10.2.6'
    compile 'com.google.firebase:firebase-core:9.2.0'
    compile 'com.google.firebase:firebase-messaging:9.2.0'
    compile 'com.bignerdranch.android:recyclerview-multiselect:+'
    compile 'com.facebook.stetho:stetho:1.5.0'
    compile 'com.uphyca:stetho_realm:2.0.0'
    compile 'com.lapism:searchview:4.0'
    compile 'com.miguelcatalan:materialsearchview:1.4.0'
    compile 'com.github.arimorty:floatingsearchview:2.1.1'
    compile 'me.philio:pinentryview:1.0.6'
    compile 'com.alimuzaffar.lib:pinentryedittext:1.3.1'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.github.pchmn:MaterialChipsInput:1.0.8'


    /*----- Retrofit 2 */
    compile 'com.squareup.okhttp3:okhttp:3.4.1'
    compile 'com.squareup.okhttp3:okhttp-ws:3.4.1'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.squareup.retrofit2:retrofit:2.1.0'
    compile 'com.squareup.retrofit2:converter-gson:2.1.0'
    compile 'io.reactivex.rxjava2:rxjava:2.0.2'
    compile 'io.reactivex.rxjava2:rxandroid:2.0.1'
    compile 'com.squareup.retrofit2:adapter-rxjava2:2.3.0'
    compile 'com.google.dagger:dagger:2.11'
    compile 'com.google.dagger:dagger-android:2.11'
    compile 'javax.inject:javax.inject:1'
    compile 'io.realm:android-adapters:2.0.0'
    compile 'org.parceler:parceler-api:1.1.6'
    compile 'com.jakewharton:butterknife:8.5.1'
    compile 'com.theartofdev.edmodo:android-image-cropper:2.4.+'
    compile 'com.github.yalantis:ucrop:2.2.1-native'
    compile 'jp.wasabeef:picasso-transformations:2.1.2'
    compile 'jp.co.cyberagent.android.gpuimage:gpuimage-library:1.4.1'
    compile 'com.github.dmytrodanylyk:android-morphing-button:98a4986e56'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'
    annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.0.0-RC0'
    annotationProcessor 'org.parceler:parceler:1.1.6'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
    provided 'javax.annotation:jsr250-api:1.0'
    compile 'com.mikhaellopez:circularimageview:3.0.2'          // circle image view
}


apply plugin: 'com.google.gms.google-services'

4 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,花了2-3个小时,我发现这个问题是由dex限制引起的。在 app.gradle 文件中,请进行以下更改:

defaultConfig { 
    multiDexEnabled true 
}

在内部依赖项部分添加

compile 'com.android.support:multidex:1.0.2'

,你需要做的最后一件事是,

public class YourApplication extends MultiDexApplication {
...
}

您必须使用 MultiDexApplication 而不是应用程序类。希望一些开发人员使用这个解决方案。

答案 1 :(得分:0)

在我的情况下,我正在更新Gradle版本,所以我在依赖项中有以下几行:

compileOnly 'com.google.dagger:dagger:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
testAnnotationProcessor "com.google.dagger:dagger-compiler:2.11"

但是基于一个教程,我找到了这一行,问题就解决了。

implementation 'com.google.dagger:dagger:2.11'
implementation 'com.google.dagger:dagger-android-support:2.11'
annotationProcessor 'com.google.dagger:dagger-compiler:2.11'
annotationProcessor 'com.google.dagger:dagger-android-processor:2.11'

答案 2 :(得分:0)

您必须维护

的multidex库

将此gradle添加到您的依赖项中

dependencies {
 compile 'com.android.support:multidex:1.0.1'
} 

并在

中启用multidex
 android {
   defaultConfig {
    ...
    minSdkVersion 21 
    targetSdkVersion 26
    multiDexEnabled true // check it carefully 
 }
...
}

现在您必须创建一个MyApplication类并将其扩展到Application

 public class MyApplication extends Application {
  @Override
  protected void Create() {
    MultiDex.install(this);
  }
}

并将其定义为您的清单,如

 <application
        android:name=".MyApplication" >
    ...
</application>

现在构建您的项目并尝试运行。我想现在你的问题将得到解决

答案 3 :(得分:-1)

如果应用程序中的任何 sdk 使用了 dagger 依赖项,那么即使应用程序也应该添加 应用级 build.gradle 文件中的 dagger 依赖项

在我的场景中,SDK 使用了 dagger 依赖项。但我没有在我的应用中包含 dagger 依赖项。

在应用程序中包含 dagger 依赖项后,问题解决了。