【问题标题】:Build fails due to missing dx.jar由于缺少 dx.jar,构建失败
【发布时间】:2016-05-18 06:54:53
【问题描述】:

每当我尝试构建项目时,它都会显示以下错误,

Error:Execution failed for task ':app:transformClassesWithDexForDebug'>  com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.IllegalStateException: dx.jar is missing

我最近更新了我的 sdk,然后卸载了 android studio,取消选中 sdk 并下载了没有 sdk 的 IDE(只是因为我想更新 studio),并让它使用当前的 sdk。

请帮忙!我还没有找到任何可行的解决方案。

【问题讨论】:

  • 你试过 Build -> Clean Project 吗?
  • 是的@dionellorera
  • 更新 SDK 平台和构建工具
  • 没有更新选项,我已经有更新的了

标签: android android-sdk-tools android-studio-2.1 dx


【解决方案1】:

您是否也更新了 build.gradle?

样本:

android {
    compileSdkVersion 24 // this is important
    buildToolsVersion "24" // this also

    defaultConfig {
        applicationId "org.bamboomy.yarne"
        minSdkVersion 15
        targetSdkVersion 24 // recommended
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.0.0' // and don't forget this
    compile 'com.android.support:design:24.0.0' // and this
}

我不是专家,但似乎在

C:\Users\myusername\AppData\Local\Android\sdk\build-tools\23.0.2

dir没有dx.jar(只有一个dx.bat)

从 23.0.3 开始,似乎有一个

C:\Users\myusername\AppData\Local\Android\sdk\build-tools\23.0.3\lib

存在 dx.jar 的文件夹

【讨论】:

    【解决方案2】:

    删除 sdk 平台工具和构建工具并重新安装它们对我有用。

    【讨论】:

      【解决方案3】:

      将此添加到您的 build.gradle

      android {
      ...
      defaultConfig {
          ...
          multiDexEnabled true
          }
      }
      

      check this asnwer too

      【讨论】:

      • 我认为,我提到的链接应该可以工作,您是否尝试过该链接的答案。@UrjaPawar
      • 该错误与dex方法限制无关,故此答案不适用。
      • 您是否已在我的回答中检查了上述链接中的所有答案?@UrjaPawar
      猜你喜欢
      • 2022-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-19
      相关资源
      最近更新 更多