从 1.4.0 开始,现在无法访问 Dex

Access to the Dex is now impossible, starting with 1.4.0

当我想同步时 gradle 我收到这个错误:

Error:Access to the dex task is now impossible, starting with 1.4.0
1.4.0 introduces a new Transform API allowing manipulation of the .class files.
See more information: http://tools.android.com/tech-docs/new-build-system/transform-api

当我点击 link 时,我没有找到任何解决方案。 谁有解决办法 谢谢

尝试将您的 gradle 版本降级到 1.3.0

在 build.gradle 文件

的依赖项部分将您的 gradle 版本明确设置为 1.3.0
classpath 'com.android.tools.build:gradle:1.3.0'

正如其他答案中所建议的那样,降级是一种选择。但是,这不是解决方案。正如 David Argyle Thacker 所问,如果我们真的想使用更新版本(gradle 构建工具)怎么办?

我在升级我的一个项目中的 gradle 工具版本时遇到了同样的问题。所以,我做了以下操作,瞧,它起作用了。

  1. 将所有库(来自 Google Play 服务和支持库的依赖项以及使用的其他 SDK)更新到最大可用版本。如果您使用的是 NewRelic,请更新到最新版本。
  2. 将 multiDexEnabled true 添加到 /app/build.gradle.

    中的 defaultConfig
    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        multiDexEnabled true
    }
    
  3. 删除您之前为使 MultiDexing 工作而编写的所有代码。 例如,

    • 移除 MultiDex 的 afterEvaluate

      afterEvaluate {
          tasks.matching {
              it.name.startsWith('dex')
          }.each { dx ->
              if (dx.additionalParameters == null) {
                  dx.additionalParameters = []
          }
          dx.additionalParameters += '--multi-dex'
      
          // this is optional
          //  dx.additionalParameters += "--main-dex-list=$projectDir/multidex-classes.txt".toString()
          }
      }
      
    • 移除multidex依赖

      dependencies {
          ...
          compile 'com.android.support:multidex:1.0.1'
      }
      
    • AndroidManifest.xml 中删除代码

      <?xml version="1.0" encoding="utf-8"?>
      <manifest xmlns:android="http://schemas.android.com/apk/res/android"
              package="com.example.pcsalt.multidex">
          <application
                  ...
              android:name="android.support.multidex.MultiDexApplication">
                  ...
          </application>
      </manifest>
      
    • 如果您通过扩展 android.app.Application 使用自定义应用程序 class,则删除 MultiDex.install(base);

      @Override
      protected void attachBaseContext(Context base) {
              super.attachBaseContext(base);
              MultiDex.install(base);
      }
      
  4. 在 /build.gradle

    中将构建工具版本更新为 2.1.2(撰写本文时可用的最高稳定版本)
    classpath 'com.android.tools.build:gradle:2.1.2'
    
  5. Gradle 通过单击立即同步来同步项目

希望这对您有所帮助。

http://www.pcsalt.com/android/solution-access-dex-task-now-impossible-starting-1-4-0