java.lang.NoClassDefFound使用Dagger 2 for Android 4

我有一个使用Dagger 2的项目,我无法在 Android 4上运行应用程序,它崩溃了.但是在Android 5上它运行得很好.所以这是我得到的错误
08-05 05:03:38.076  25444-25444/app.xqute.com.xqute E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: app.xqute.com.xqute,PID: 25444
java.lang.NoClassDefFoundError: app.xqute.com.xqute.AppModule_ProvideProfileFactory
        at app.xqute.com.xqute.DaggerApp_AppComponent.initialize(DaggerApp_AppComponent.java:58)
        at app.xqute.com.xqute.DaggerApp_AppComponent.<init>(DaggerApp_AppComponent.java:50)
        at app.xqute.com.xqute.DaggerApp_AppComponent.<init>(DaggerApp_AppComponent.java:35)
        at app.xqute.com.xqute.DaggerApp_AppComponent$Builder.build(DaggerApp_AppComponent.java:151)
        at app.xqute.com.xqute.App.onCreate(App.java:63)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
        at android.app.ActivityThread.access$1500(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5001)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
        at dalvik.system.NativeStart.main(Native Method)

这是build.gradle文件,其中包含我正在使用的设置:

apply plugin: 'com.android.application'
 apply plugin: 'me.tatarka.retrolambda'
 apply plugin: 'com.neenbedankt.android-apt'






 android {
compileSdkVersion 22
buildToolsversion "22.0.1"

defaultConfig {
    applicationId "app.xqute.com.xqute"
    multiDexEnabled = true
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

 signingConfigs {
    release {
        storeFile file("xQute.jks")
        storePassword "saswat123"
        keyAlias "xQute"
        keyPassword "saswat123"
    }

 }

buildTypes {
    release {
        minifyEnabled false
        shrinkResources true
        proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
lintOptions {
      abortOnError false
  }



 }


 dependencies {
compile filetree(include: ['*.jar'],dir: 'libs')
apt "com.google.dagger:dagger-compiler:2.0"
provided 'javax.annotation:jsr250-api:1.0'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
androidTestCompile 'org.assertj:assertj-core:1.6.1'
androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
testCompile 'junit:junit:4.12'
testCompile 'org.assertj:assertj-core:1.6.1'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.google.dagger:dagger:2.0'
compile 'com.jakewharton.timber:timber:3.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.jakewharton:butterknife:6.1.0'
compile 'com.facebook.fresco:fresco:0.5.0'
compile 'com.google.android.gms:play-services:7.5.0'
compile 'com.rengwuxian.materialedittext:library:2.1.3'
compile 'com.github.rey5137:material:1.1.1'
compile 'com.android.support:support-v4:22.2.0'
compile 'com.android.support:recyclerview-v7:22.2.0'
testCompile 'org.mockito:mockito-core:1.10.19'
compile files('libs/Parse-1.9.2.jar')
 }

 configurations {
compile.exclude module: 'support-annotations'
 }

任何想法为什么它适用于Android 5但不适用于Android 4?

解决方法

对于低于21的android API级别,您需要在构建gradle文件添加以下依赖项,并且需要将Application类更改为MultiDexApplication,如下所示:

在app build.gradle文件中:

Implementation 'com.android.support:multidex:1.0.3'

在您的BaseApplication中将Application类更改为MultiDexApplication:

public class BaseApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...