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

时间:2015-09-15 06:32:14

标签: android android-gradle

当我想同步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

当我点击链接时,我找不到任何解决方案。 任何人都有解决方案谢谢。

3 个答案:

答案 0 :(得分:7)

将builddle格式显式设置为build.gradle文件的依赖项部分中的1.3.0

classpath 'com.android.tools.build:gradle:1.3.0'

答案 1 :(得分:1)

正如其他答案中所建议的那样,降级是一种选择。但是,它不是一个解决方案。正如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来使用自定义Application类,则删除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通过单击立即同步

  6. 同步项目

    希望这会有所帮助。

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

答案 2 :(得分:0)

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