【问题标题】:Android Studio Gradle Error - preDexDebugAndroid Studio Gradle 错误 - preDexDebug
【发布时间】:2017-01-08 13:48:06
【问题描述】:

我最近在我的 android studio 项目中添加了一个新活动,现在我在尝试运行它时遇到错误。它构建得很好,但是当我运行它时出现以下错误:

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

这是我的 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')
}

我已尝试删除 supportLappcompat 依赖项,但随后出现更多错误。非常感谢任何帮助。

【问题讨论】:

  • 尝试添加依赖:compile 'com.android.support:support-v4:20.+'
  • 恐怕这行不通。我仍然有同样的错误

标签: android android-studio android-gradle-plugin build.gradle


【解决方案1】:

我终于通过下载最新版本的gradle解决了这个问题。

我仍然经常遇到这个错误,我只是通过转到文件来修复它---->使缓存无效/重新启动

我发现 Android Studio 有很多问题

【讨论】:

    【解决方案2】:

    基于它试图找到 dx 命令的位置:

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

    看起来您已经将构建工具版本与其他东西交叉。您在问题中发布的构建文件看起来不错,但请查看项目中的其他构建文件(至少在libraries/zbar 中会有一些东西)并确保他们的buildToolsVersion 语句没问题。我怀疑你有什么地方:

    buildToolsVersion 'android-4.4W'
    

    你应该有的地方:

    buildToolsVersion '20.0.0'
    

    【讨论】:

    • 不,那没用。我认为我要么缺少正确的依赖关系,要么像你说的那样存在冲突。谢谢
    【解决方案3】:

    现在我知道问题的原因了。这是\sdk\android-sdk\tools\lib\find_java.bat中的错误代码引起的

    错误代码:

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

    正确代码:

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

    错误的代码导致java_exe的路径是

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

    所以,当dx.bat 运行时

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

    会报错状态:

    Error Code:
        1
    

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

    【讨论】:

    • 这是工具 24 中的一个错误
    【解决方案4】:

    我遇到了类似的问题,所以我卸载了 java jdk 并从 oracle 重新安装了最新版本,一切正常。安装最新版jdk的链接是here

    注意:以上操作后需要更新android studio中的jdk目录

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-15
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-23
      相关资源
      最近更新 更多