Error:Execution failed for task ':app:dexDebug'. finished with non-zero exit value 2 with Facebook Fresco

Error:Execution failed for task ':app:dexDebug'. finished with non-zero exit value 2 with Facebook Fresco

我在这里阅读了关于这个问题的每一个话题,但我找不到我的问题的任何答案。

添加 Fresco 库后,我在构建我的应用程序时遇到此错误。 有问题的行是:compile 'com.facebook.fresco:fresco:0.5.3+' 错误:

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.7.0_71\bin\java.exe'' finished with non-zero exit value 2

如果我去掉 fresco 编译行,它就可以工作了。

我的 gradle 看起来像这样:

buildscript {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
        //classpath 'org.robolectric:robolectric-gradle-plugin:1.1.0'
    }
}

allprojects {
    repositories {
        mavenCentral()
        maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    }
}

apply plugin: 'com.android.application'
//apply plugin: 'org.robolectric'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"
    defaultConfig {
        applicationId "com.maddogs.mymoney"
        minSdkVersion 11
        targetSdkVersion 22
        //testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }
    sourceSets {
        androidTest {
            setRoot('src/test') //note that this is androidTest instead of instrumentTest
        }
    }

    productFlavors {
    }

    lintOptions {
        abortOnError false
    }
}

dependencies {

    compile 'com.facebook.fresco:fresco:0.5.3+'
    compile 'com.facebook.android:facebook-android-sdk:4.3.0'

    compile 'com.facebook.stetho:stetho:1.1.1'
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'de.greenrobot:eventbus:2.4.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.jakewharton:butterknife:6.1.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
    compile 'com.bignerdranch.android:recyclerview-multiselect:+'
    compile files('libs/Parse-1.9.2.jar')
    compile files('libs/ParseCrashReporting-1.9.2.jar')
    compile files('libs/ParseFacebookUtilsV4-1.9.2.jar')
}

提前致谢!

有时,当一个库被多次包含在您的项目中时,会显示 app:dexDebug 错误。当错误与您的应用程序中的任何依赖项无关时,则可能是 65k 方法限制问题。 Dalvik Executable 规范限制了方法的总数,您可以阅读更多相关内容 here

修改您的应用 Gradle 构建文件配置以包含支持库并启用 multidex 输出,如以下 Gradle 构建文件片段所示:

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.0"

    defaultConfig {
        ...
        minSdkVersion 14
        targetSdkVersion 21
        ...

        // Enabling multidex support.
        multiDexEnabled true
    }
    ...
}

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