简体   繁体   English

Android Studio Gradle Error - preDexDebug

[英]Android Studio Gradle Error - preDexDebug

I recently added a new activity to my android studio project and now I am getting an error when I try and run it. 我最近在我的android studio项目中添加了一个新活动,现在我在尝试运行它时遇到错误。 It builds fine but I get the error below when I run it: 它构建正常但我在运行它时得到以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:preDexDebug'.
> com.android.ide.common.internal.LoggedErrorException: Failed to run command:
    /Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx --dex --output /Users/davidcavanagh/joshcpdandroid/app/build/intermediates/pre-dexed/debug/classes-22ecb8c50fefe43948d87c9fee8e36a6b7d1bb5a.jar /Users/davidcavanagh/joshcpdandroid/app/build/intermediates/exploded-aar/com.android.support/support-v4/20.0.0/classes.jar
  Error Code:
    1

Here is my build.gradle file 这是我的build.gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion '20.0.0'

    defaultConfig {
        applicationId "com.joshcpd.android"
        minSdkVersion 15
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.google.android.gms:play-services:5.2.08'
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile project(':libraries:zbar')
}

I have tried removing the supportLappcompat dependency but then I get even more errors. 我已经尝试删除supportLappcompat依赖项,但后来我遇到了更多错误。 Any help greatly appreciated. 任何帮助非常感谢。

I finally solved this issue by downloading the latest version of gradle. 我终于通过下载最新版本的gradle解决了这个问题。

I still get this error every so often and I just fix it by going to File ----> Invalidate caches/restart 我仍然经常得到这个错误,我只是通过转到File ----> Invalidate caches / restart来修复它

I find Android Studio to be very buggy 我发现Android Studio非常缺陷

Based on where it's trying to find the dx command: 基于它试图找到dx命令的位置:

/Applications/Android Studio.app/sdk/build-tools/android-4.4W/dx / Applications / Android Studio.app/sdk/build-tools/android-4.4W/dx

it looks like you've crossed a build tools version with something else. 看起来你已经越过了其他东西的构建工具版本。 The build file you posted in your question looks okay, but look in the other build files in your project (there's at least going to be something in libraries/zbar ) and make sure their buildToolsVersion statements are okay. 您在问题中发布的构建文件看起来没问题,但查看项目中的其他构建文件(至少会在libraries/zbar )并确保它们的buildToolsVersion语句没问题。 I suspect somewhere you have: 我怀疑你有的地方:

buildToolsVersion 'android-4.4W'

where you should have: 你应该在哪里:

buildToolsVersion '20.0.0'

Now i know the reason of the problem. 现在我知道问题的原因了。 It was causes by wrong code in \\sdk\\android-sdk\\tools\\lib\\find_java.bat 它是由\\sdk\\android-sdk\\tools\\lib\\find_java.bat的错误代码引起的

Wrong code: 错误代码:

find /i "x86" > NUL && set arch_ext=32 || set arch_ext=64

Correct code: 正确的代码:

find /i "x86" > NUL && set arch_ext=32||set arch_ext=64

The wrong code leads to the path of java_exe be 错误的代码导致java_exe的路径

E:\Android\sdk\ANDROI~1\tools\lib\\find_java32 .exe

So, when dx.bat runs 所以,当dx.bat运行时

call "%java_exe%" %javaOpts% -Djava.ext.dirs="%frameworkdir%" -jar "%jarpath%" %params% 

it will report the wrong status: 它会报告错误的状态:

Error Code:
    1

My platform: win8-32 bit android studio 1.0 - 4GB RAM 我的平台:win8-32位android studio 1.0 - 4GB RAM

I had a similar issue, so I uninstalled the java jdk and reinstalled the latest version from oracle and everything went OK. 我有一个类似的问题,所以我卸载了java jdk并从oracle重新安装了最新版本,一切顺利。 The link for installing the latest version of jdk is here 安装最新版本的jdk的链接就在这里

Note: you need to update the jdk directory in android studio after doing the above 注意:完成上述操作后,需要更新android studio中的jdk目录

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM