Android 错误:任务';的执行失败:应用程序:dexDebug';添加新依赖项时,项目中出现错误

Android 错误:任务';的执行失败:应用程序:dexDebug';添加新依赖项时,项目中出现错误,android,android-gradle-plugin,build.gradle,Android,Android Gradle Plugin,Build.gradle,我没有在我的项目中添加任何库/jar(在libs中),只是添加了此依赖项。 我的build.gradle文件 android { compileSdkVersion 23 buildToolsVersion "23.0.1" defaultConfig { applicationId "com.android.example23" minSdkVersion 14 targetSdkVersion 23 versionCode 1 versionName

我没有在我的项目中添加任何库/jar(在libs中),只是添加了此依赖项。

我的build.gradle文件

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
    applicationId "com.android.example23"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),    'proguard-rules.pro'
     }
 }
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:cardview-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile 'com.melnykov:floatingactionbutton:1.1.0'
compile 'com.android.support:design:23.1.1'
compile 'org.apache.directory.studio:org.apache.commons.io:2.4'
compile 'com.google.android.gms:play-services:8.3.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.parse:parse-android:1.11.0'
compile 'com.naver.android.helloyako:imagecropview:1.0.3'
compile 'com.squareup.okhttp:okhttp:2.6.0'
}
一旦我将这个“compile'com.squareup.okhttp:okhttp:2.6.0”添加到我的项目中,我就得到了这个

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.8.0_45\bin\Java.exe''以非零退出值2结束

运行项目时出错

如果我删除这个“compile'com.squareup.okhttp:okhttp:2.6.0'”依赖项,我的程序工作正常

有时,如果我添加了Facebook依赖项,同样的错误也会出现


首先,您可以使用
编译'com.squareup.okhttp:okhttp:2.5.0'
而不是您的。你可以阅读我的答案

android {
    compileSdkVersion 23
buildToolsVersion "23.0.1"

         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22

             // Enabling multidex support.
             multiDexEnabled true
         }
}

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


在编译之前的渐变中…

您也可以使用以下代码和IntelliJ Amiya答案。 在某些情况下,此代码对我有效

 dexOptions {
    incremental true
    javaMaxHeapSize "4g"
}

android {
compileSdkVersion 23
 buildToolsVersion "23.0.1"

     defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }
}
您可以通过创建一个应用程序类来实现

public class MyApplication extends MultiDexApplication { .. }

否则(如果您的应用程序没有自定义应用程序实现),请在AndroidManifest.xml中将MultiDexApplication声明为应用程序实现

<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>

..

发布你的全部错误我添加了一个带有错误的图像@aashv最终我得到了它,这要感谢IntelliJ Amiya和Aashvi….@Ram23你添加了
多索引启用了吗?然后清理、构建和同步您的项目刚才我添加了“multiDexEnabled true”。现在我得到了java.lang.NoClassDefFoundError的新异常:android.support.v7.appcompat正在检查此感谢@IntelliJ AmiyaI更改为23.0.0,现在我在解析中得到了新的“java.lang.NoClassDefFoundError:com.parse.gcmregistar$Singleton”错误…:(:(…@Ram23我的荣幸。你可以阅读我的答案好的,谢谢@IntelliJ AmiyaThank你的支持@Aashvi我添加了“multiDexEnabled true”,错误消失了。现在我在java.lang.NoClassDefFoundError中得到了新的错误:android.support.v7.appcompat.R$layout@Ram23我还添加了一些其他方法,可以帮助您解决这个错误。在您的回答中,我提出了一个小建议,添加一个类似“multiDexEnabled true”的注释在build.gradle中。我没有添加,因为IntelliJ Amiya已经添加了那个答案。但我现在更新了,@IntelliJ Amiya添加了…一半答案在那个帖子中,一半在你的帖子中…所以,这是y…我告诉过。。。
override 
 attachBaseContext method and call MultiDex.install().
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
<application
android:name="android.support.multidex.MultiDexApplication"
.. >
..
</application>