Android Studio:意想不到的顶级例外:

我该如何解决这个错误

错误:任务’:app:dexDebug’的执行失败。 com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:进程’命令’/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java”完成非零退出值2

App Build.gradle

apply plugin: 'com.android.application' android { compileSdkVersion 22 buildToolsVersion "22.0.1" packagingOptions { exclude 'META-INF/DEPENDENCIES' exclude 'META-INF/ASL2.0' exclude 'META-INF/NOTICE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/license.txt' exclude 'META-INF/notice.txt' } defaultConfig { applicationId "com.app" minSdkVersion 10 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile 'com.android.support:appcompat-v7:22.1.1' // Do NOT use 22.2.0 even it is newer one. It reported to cause some problems with other dependencies. compile fileTree(dir: 'libs', include: '*.jar') compile('com.google.android.gms:play-services:7.5.+') { exclude module: 'support-v4' } compile group:'com.octo.android.robospice', name:'robospice-spring-android', version:'1.4.7' compile 'com.octo.android.robospice:robospice-spring-android:1.4.7' compile group:'org.codehaus.jackson', name:'jackson-mapper-asl', version:'1.9.11' compile 'com.fasterxml.jackson.core:jackson-databind:2.2.2' compile 'com.fasterxml.jackson.core:jackson-annotations:2.2.2' compile 'com.fasterxml.jackson.core:jackson-core:2.2.2' compile 'com.google.code.gson:gson:2.2.4' compile 'com.octo.android.robospice:robospice-ormlite:1.4.6' compile('org.simpleframework:simple-xml:2.7.1') { // exclude module: 'xpp3' // exclude group: 'stax' exclude group: 'xpp3', module: 'xpp3' exclude group: 'stax', module: 'stax' exclude group: 'stax', module: 'stax-api' } } 

项目gradle

 // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() } } 

Android Mainfest

                            

Libs文件夹没有Libs文件夹现在存在

欢迎。 你正处于Android gradle地狱的第一步。

  1. 将SDK Manager中的Android SDK组件更新为最新版本,包括Extra> Google Repository(建议在Extra中添加几乎所有内容)。

  2. 让我们洗掉你当前的文件。

    • AndroidManifest.xml :删除行。 它是多余的,因为gradle文件已经定义了它。

    • Build.gradle :注释所有compile files('libs/xxxxxxx.jar')行。 第一行compile fileTree(dir: 'libs', include: ['*.jar'])将包含libs文件夹中的所有jar文件。 并且,使用maven存储库compile而不是jar文件,以保持新的依赖关系。

例如,SimpleXML具有存储库ID,如下所示。 将下面的代码放在compile fileTree(dir: 'libs', include: ['*.jar'])行下面,并删除libs文件夹中的’simple-xml-2.7.1.jar’文件。

 compile('org.simpleframework:simple-xml:2.7.1') { exclude module: 'stax' exclude module: 'stax-api' exclude module: 'xpp3' } 

同样,在libs文件夹中找到每个jar文件的存储库id,并在compile fileTree(dir: 'libs', include: ['*.jar'])行的下面compile fileTree(dir: 'libs', include: ['*.jar'])替换它。 使只有无法在maven存储库中找到的jar文件保留在libs文件夹中。

最后,删除proguardFiles行。 您需要在一般条件下找到并修复问题,然后再应用progruard。

  1. 将buildToolsVersion和compileSdkVersion的版本设置为最新版本。

我今天的建议如下,
(如果有人将来看到这篇文章,数字可能会有所不同)

 android { compileSdkVersion 22 buildToolsVersion '22.0.1' dexOptions { preDexLibraries = false javaMaxHeapSize "2g" } defaultConfig { ... multiDexEnabled = false } lintOptions { abortOnError false disable 'InvalidPackage' } ... } dependencies { compile 'com.android.support:appcompat-v7:22.1.1' // Do NOT use 22.2.0 even it is newer one. It reported to cause some problems with other dependencies. compile fileTree(dir: 'libs', include: '*.jar') compile('com.google.android.gms:play-services-gcm:7.5.+') { exclude module: 'support-v4' } } 
  1. 命令gradle assembleDebug再次。 (对于Windows, gradlew assembleDebug

  2. 如果再次失败,请尝试逐个查找并修复依赖项版本冲突问题。 您可能会在我的代码中看到exclude module: ... 这些解决了冲突问题。 有关详细说明,请访问以下链接: https : //stackoverflow.com/a/30649660/361100

您是否尝试在build.gradle中注释掉以下内容:

 //compile fileTree(dir: 'libs', include: ['*.jar']) 

参考: https : //code.google.com/p/android/issues/detail? id = 161605

令人惊讶的是,这个对我有用

 defaultConfig { multiDexEnabled true } 

来源: Android Studio无法使用错误org.gradle.process.internal.ExecException进行调试

当我导入所有Google Play服务API时,我发生了同样的错误

compile('com.google.android.gms:play-services:7.5.+')

尝试删除此行并仅导入所需的服务API: Google Play服务设置