错误:在将项目从Eclipse导入到Android Studio之后,任务':app:dexDebug'的执行失败

错误:在将项目从Eclipse导入到Android Studio之后,任务':app:dexDebug'的执行失败

问题描述:

我将一个项目从Eclipse导入到Android。然后我尝试运行应用程序时收到此错误消息:

I imported a project from Eclipse to Android. Then I get this error message after I tried to run application:


错误:执行失败的任务':app:dexDebug'。
com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:Process'command'C:\Program Files(x86)\Java\jdk1.8.0_40\ bin \java.exe完成了非零退出值2

Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files (x86)\Java\jdk1.8.0_40\bin\java.exe'' finished with non-zero exit value 2

看起来像这样的问题:
错误:任务':app:dexDebug'的执行失败。 com.android.ide.common.process.ProcessException

It seems like this problem: Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException

但我试过所有的答案,没有一个工作。

But I tried all of the answers and none of them worked.

这是我的build.gradle

Here is my build.gradle

apply plugin: 'com.android.application'

android {
  compileSdkVersion 21
  buildToolsVersion "22.0.1"
  compileOptions.encoding = 'windows-1251'

  defaultConfig {
    applicationId "sk.app"
    minSdkVersion 15
    targetSdkVersion 21
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
  }

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

dependencies {
  compile 'com.android.support:support-v4:23.1.1'
  compile 'com.google.code.gson:gson:2.3'
  compile files('libs/activation.jar')
  compile files('libs/droidText.0.4.jar')
  compile files('libs/google-play-services.jar')
  compile files('libs/mail.jar')
}


我有这个ProcessException.From我看到它主要是由于64k方法的限制。这可能是因为您的项目添加了如此多的库,这也可能意味着很少的库是重复的。

I had this ProcessException.From what I have seen it is mainly due to the 64k method limitation. This may occur because your project has so many libraries added which may also mean that few of them are duplicate.

问题我有64k限制,因为通过PlayServices包括重复的依赖关系。 当buildToolsVersion更改为22.0.1到23.0.1 是我的问题在SOF回答。

Issue I had was 64k limitation crossed because of duplicate dependencies included through PlayServices. ProcessException when buildToolsVersion is changed from 22.0.1 to 23.0.1 is my issue answered in SOF.

我认为在你的情况下,似乎不是一个问题。但仍然可以启用multidex。您也可以按照使用超过65K方法构建应用

I think in your case that does not seem to be an issue for me. But still you can have multidex enabled. Do that too by following Building Apps with Over 65K Methods.

同时尝试最新的构建工具版本,它是来自 build-tools

Also try the latest build tools version which is 23.0.2 from build-tools.

EDIT

对于@EsoRimmer,但最新的构建工具版本以及它使它的工作。因此,使用最新的构建工具总是一种避免不必要问题的方法。

For @EsoRimmer, it did not work just with MultiDex enabled but latest build tools version along with it made it work. So, using the latest build tools always a way to avoid unnecessary issues.