Android Studio:意外的顶级异常:
Android Studio : UNEXPECTED TOP-LEVEL EXCEPTION:
如何解决这个错误
Error:Execution failed for task ':app:dexDebug'.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
应用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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app" >
<!-- Permission - Internet Connect -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- Permission - Location - GPS Service -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Call Phone Permissions -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:name=".app.AppHelper"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service
android:name="com.octo.android.robospice.Jackson2SpringAndroidSpiceService"
android:exported="false" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCU__5jhNC-QaU9tXNpr7ikPio3km1UYe8" />
<activity
android:name=".ui.splash.SplashActivity"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.base.BaseDrawerFragmentActivity"
android:configChanges="locale"
android:label=""
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
</activity>
</application>
库文件夹
现在不存在 Libs 文件夹
您是否尝试过在 build.gradle 中注释掉以下内容:
//compile fileTree(dir: 'libs', include: ['*.jar'])
参考:https://code.google.com/p/android/issues/detail?id=161605
欢迎。你正处于 Android gradle 地狱的第一步。
将 SDK Manager 中的 Android SDK 组件更新为最新版本,包括 Extra > Google Repository(建议在 Extra 中添加几乎所有组件)。
让我们清理你当前的文件。
AndroidManifest.xml:删除 <uses-sdk ... />
行。它是多余的,因为 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'])
行下方。仅使在 maven 存储库中找不到的 jar 文件保留在 libs 文件夹中。
最后,删除 proguardFiles
行。您需要在一般情况下找到并解决问题,然后再应用程序。
- 将buildToolsVersion和compileSdkVersion的版本设置为最新版本。
我今天的推荐如下,
(将来有人看到这个 post 时,数字可能会有所不同)
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'
}
}
再次命令 gradle assembleDebug
。 (对于 Windows、gradlew assembleDebug
)
如果再次失败,请尝试逐一查找并修复依赖版本冲突问题。您可能会在我的代码中看到 exclude module: ...
。这些解决了冲突问题。详细说明在 link:
令人惊讶的是这个对我有用
defaultConfig {
multiDexEnabled true
}
来源:
当我导入所有 Google Play 服务 API 时,我也遇到了同样的错误,就像您导入
compile('com.google.android.gms:play-services:7.5.+')
尝试删除此行并仅导入您需要的服务 API:Google Play Services Setup
如何解决这个错误
Error:Execution failed for task ':app:dexDebug'. com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/Library/Java/JavaVirtualMachines/jdk1.7.0_67.jdk/Contents/Home/bin/java'' finished with non-zero exit value 2
应用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
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app" >
<!-- Permission - Internet Connect -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<!-- Permission - Location - GPS Service -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Network State Permissions -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Call Phone Permissions -->
<uses-permission android:name="android.permission.CALL_PHONE" />
<application
android:name=".app.AppHelper"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service
android:name="com.octo.android.robospice.Jackson2SpringAndroidSpiceService"
android:exported="false" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCU__5jhNC-QaU9tXNpr7ikPio3km1UYe8" />
<activity
android:name=".ui.splash.SplashActivity"
android:label="@string/app_name"
android:noHistory="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.base.BaseDrawerFragmentActivity"
android:configChanges="locale"
android:label=""
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">
</activity>
</application>
库文件夹 现在不存在 Libs 文件夹
您是否尝试过在 build.gradle 中注释掉以下内容:
//compile fileTree(dir: 'libs', include: ['*.jar'])
参考:https://code.google.com/p/android/issues/detail?id=161605
欢迎。你正处于 Android gradle 地狱的第一步。
将 SDK Manager 中的 Android SDK 组件更新为最新版本,包括 Extra > Google Repository(建议在 Extra 中添加几乎所有组件)。
让我们清理你当前的文件。
AndroidManifest.xml:删除
<uses-sdk ... />
行。它是多余的,因为 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'])
行下方。仅使在 maven 存储库中找不到的 jar 文件保留在 libs 文件夹中。
最后,删除 proguardFiles
行。您需要在一般情况下找到并解决问题,然后再应用程序。
- 将buildToolsVersion和compileSdkVersion的版本设置为最新版本。
我今天的推荐如下,
(将来有人看到这个 post 时,数字可能会有所不同)
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'
}
}
再次命令
gradle assembleDebug
。 (对于 Windows、gradlew assembleDebug
)如果再次失败,请尝试逐一查找并修复依赖版本冲突问题。您可能会在我的代码中看到
exclude module: ...
。这些解决了冲突问题。详细说明在 link:
令人惊讶的是这个对我有用
defaultConfig {
multiDexEnabled true
}
来源:
当我导入所有 Google Play 服务 API 时,我也遇到了同样的错误,就像您导入
compile('com.google.android.gms:play-services:7.5.+')
尝试删除此行并仅导入您需要的服务 API:Google Play Services Setup