错误:在我添加新依赖项时,我的项目中的任务 ':app:dexDebug' 错误执行失败 [英] Error:Execution failed for task ':app:dexDebug' error in my project while I added new dependency

查看:15
本文介绍了错误:在我添加新依赖项时,我的项目中的任务 ':app:dexDebug' 错误执行失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有在我的项目中(在 libs 中)添加任何库/罐子,只有这个依赖项.

我的 build.gradle 文件.

<代码>android {compileSdkVersion 23构建工具版本23.0.1"默认配置 {应用程序IDcom.android.example23"minSdkVersion 14targetSdkVersion 23版本代码 1版本名称1.0"}构建类型 {发布 {缩小启用假proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'}}}依赖{编译文件树(包括:['*.jar'],目录:'libs')测试编译'junit:junit:4.12'编译'com.android.support:appcompat-v7:23.1.1'编译'com.android.support:cardview-v7:23.1.1'编译'com.android.support:recyclerview-v7:23.1.1'编译'com.android.support:support-v4:23.1.1'编译 'com.melnykov:floatingactionbutton:1.1.0'编译'com.android.support:design:23.1.1'编译'org.apache.directory.studio:org.apache.commons.io:2.4'编译'com.google.android.gms:play-services:8.3.0'编译'com.squareup.picasso:picasso:2.5.2'编译'com.parse:parse-android:1.11.0'编译'com.naver.android.helloyako:imagecropview:1.0.3'编译'com.squareup.okhttp:okhttp:2.6.0'}

一旦我将这个compile 'com.squareup.okhttp:okhttp:2.6.0'"添加到我的项目中,我就会得到这个

错误:任务 ':app:dexDebug' 执行失败.

<块引用>

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:Program FilesJavajdk1.8.0_45injava.exe'' 完成非零退出值 2

运行项目时出现错误....

如果我删除这个compile 'com.squareup.okhttp:okhttp:2.6.0'"依赖,我的程序就可以正常工作了.

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

解决方案

你也可以使用下面的代码和 IntelliJ Amiya 答案.在某些情况下,这段代码对我有用

 dexOptions {增量真javaMaxHeapSize "4g"}安卓 {compileSdkVersion 23构建工具版本23.0.1"默认配置 {minSdkVersion 14//低于14不支持multidextargetSdkVersion 22//启用多索引支持.multiDexEnabled 真}}

你可以通过创建一个应用程序类来做到这一点

public class MyApplication extends MultiDexApplication { .. }

覆盖attachBaseContext 方法并调用 MultiDex.install().受保护的无效 attachBaseContext(上下文基础){super.attachBaseContext(base);MultiDex.install(this);}

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

I didn't added any libraries / jars in my project( in libs ) only this dependencies.

My build.gradle file.

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'
}

Once I am adding this " compile 'com.squareup.okhttp:okhttp:2.6.0' " into my project I am getting this

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

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:Program FilesJavajdk1.8.0_45injava.exe'' finished with non-zero exit value 2

Error is coming while I run my project....

If I remove this " compile 'com.squareup.okhttp:okhttp:2.6.0' " dependency my program is working fine.

Sometimes if I added Facebook dependency also the same error is coming...

解决方案

you can use below code also with IntelliJ Amiya answer. In some case this code work for me

 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
     }
}

you can do by make an Application class

public class MyApplication extends MultiDexApplication { .. }

or

override 
 attachBaseContext method and call MultiDex.install().
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}

Otherwise (if your application does not have custom Application implementation), declare MultiDexApplication as application implementation in your AndroidManifest.xml.

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

这篇关于错误:在我添加新依赖项时,我的项目中的任务 ':app:dexDebug' 错误执行失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆