Android Studio无法解决错误':app:preDexDebug'

时间:2015-03-09 00:47:34

标签: java android android-studio gradle

我只是从Eclipse转移到令人生畏的Android Studio并且无法摆脱,似乎是一个相当常见的错误。

Error:Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 1

我全神贯注地尝试了各种解决方案,从简单地重新启动我的工作室,无效和清除缓存,移除JAR并尝试再次添加它们,但到目前为止没有任何作用。我是这个IDE的新手,所以我甚至不确定它是如何工作的以及构建文件应该是什么样子。

这是我当前的build.gradle(模块:app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.culami"
        minSdkVersion 21
        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:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:21.0.3'
    compile files('libs/WebSocket.jar')
    compile files('libs/android-support-v13.jar')
    compile files('libs/json-org.jar')
    compile files('libs/socketio.jar')
}

该项目是从Eclipse导入的,其原因是我遇到了json-org.jar和WebSocket.jar的一些构建问题。我无法修复此问题和issue is still open。我不确定如何通过gradle添加这些依赖项,因为github页面并没有真正说明如何。

这是Gradle控制台的输出。

Executing tasks: [:app:assembleDebug]

Configuration on demand is an incubating feature.
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug
AGPBI: {"kind":"SIMPLE","text":"UNEXPECTED TOP-LEVEL EXCEPTION:","position":{},"original":"UNEXPECTED TOP-LEVEL EXCEPTION:"}
AGPBI: {"kind":"SIMPLE","text":"com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;","position":{},"original":"com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)","position":{},"original":"\tat com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)","position":{},"original":"\tat com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)","position":{},"original":"\tat com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)","position":{},"original":"\tat com.android.dx.merge.DexMerger.merge(DexMerger.java:189)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)","position":{},"original":"\tat com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)","position":{},"original":"\tat com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)","position":{},"original":"\tat com.android.dx.command.dexer.Main.run(Main.java:246)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)","position":{},"original":"\tat com.android.dx.command.dexer.Main.main(Main.java:215)"}
AGPBI: {"kind":"SIMPLE","text":"\tat com.android.dx.command.Main.main(Main.java:106)","position":{},"original":"\tat com.android.dx.command.Main.main(Main.java:106)"}


 FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-oracle/bin/java'' finished with non-zero exit value 2

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 23.247 secs

如何修复此preDexDebug错误的任何帮助将是一个很大的帮助!作为旁注,我也无法在左侧的项目浏览器中看到我的'libs'文件夹。

2 个答案:

答案 0 :(得分:7)

你有一个jar文件或一个lib出现多次,需要使用"配置"在你的" gradle.build"

了解如何使用以下内容分析依赖关系:

./gradlew :app:dependencies

background on wrapper

./gradlew --info clean assembleDebug > ../myProj_build

将在构建文件中为您提供额外信息,您可以分析这些信息以获取有关" preDex"的详细信息。错误

答案 1 :(得分:4)

您将jar依赖项添加为编译依赖项。您应该将其添加为“已提供”,(请参阅README)。