本文介绍了Android Studio 无法解决错误“:app:preDexDebug"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚从 Eclipse 转移到令人生畏的 Android Studio 并且难以摆脱,这似乎是一个相当常见的错误.

I'm just moving on from Eclipse to the intimidating Android Studio and have trouble getting rid of, what appears to be a fairly common error.

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

我四处查看并尝试了各种解决方案,包括简单地重新启动我的 Studio、使缓存无效并清除缓存、删除 JAR 并尝试再次添加它们,但到目前为止没有任何效果.我对这个 IDE 很陌生,所以我什至不确定它是如何工作的以及构建文件应该是什么样子.

I looked all over and have tried various solutions ranging from simply restarting my Studio, Invalidating and clearing the cache, removing the JARs and trying to add them again, but so far nothing works. I'm very new to this IDE so I'm not even sure how it works and what the build files are supposed to look like.

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

Here's my current build.gradle (Module: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 方面遇到了一些构建问题.我无法解决这个问题,问题仍然存在.我不确定如何通过 gradle 添加这些依赖项,因为 github 页面并没有真正说明如何.

The project was imported from Eclipse and the reason for doing so was that I was facing some build issues with json-org.jar and WebSocket.jar. I wasn't able to fix this and the issue is still open. I'm not sure how do add these dependencies via gradle because the github page doesn't really say how.

这是 Gradle 控制台的输出.

Here's the output from the Gradle console.

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"文件夹.

Any help on how to fix this preDexDebug error will be a great help! As a side note, I'm also not able to see my 'libs' folder in the project explorer on the left.

推荐答案

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

you have a jar file or a lib appearing multiple times and need to work with "configuration" in your "gradle.build"

寻找如何使用以下内容分析依赖关系:

look for how to analyze dependencies with something like:

./gradlew :app:dependencies

包装背景

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

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

will give you extra info in a build file that you can analyze for details on your "preDex" errors

这篇关于Android Studio 无法解决错误“:app:preDexDebug"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 12:10