Access to the Dex is now impossible, starting with

2019-01-17 21:31发布

when i want to sync gradle i get this error:

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

When i click the link, i don't find any solution. Anyone have solution thanks.

3条回答
姐就是有狂的资本
2楼-- · 2019-01-17 22:20

As suggested in other answers, downgrade is one option. But, it is not a solution. As asked by David Argyle Thacker, what if we actually want to use a newer version (of gradle build tool)?

I was having same trouble while upgrading gradle tool version in one of my projects. So, I did following and voila, it worked.

  1. Update all the libraries (dependencies from Google Play Services and Support libraries along with other SDKs used) to the max available version. If you are using NewRelic, then update to the latest version.
  2. Add multiDexEnabled true to the defaultConfig in /app/build.gradle.

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 1
        multiDexEnabled true
    }
    
  3. Remove all the code you have previously written to get MultiDexing to work. For instance,

    • Remove the afterEvaluate block for MultiDex

      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()
          }
      }
      
    • Remove multidex dependency

      dependencies {
          ...
          compile 'com.android.support:multidex:1.0.1'
      }
      
    • Remove the code from 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>
      
    • If you are using custom Application class by extending android.app.Application, then remove MultiDex.install(base);

      @Override
      protected void attachBaseContext(Context base) {
              super.attachBaseContext(base);
              MultiDex.install(base);
      }
      
  4. Update the build tool version to 2.1.2 (highest stable version available at the time of writing) in /build.gradle

    classpath 'com.android.tools.build:gradle:2.1.2'
    
  5. Gradle Sync the project, by clicking Sync now

Hope this helps.

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

查看更多
相关推荐>>
3楼-- · 2019-01-17 22:26

Try downgrading your gradle version to 1.3.0

查看更多
Melony?
4楼-- · 2019-01-17 22:30

set your gradle version explicitly to 1.3.0 in dependencies section of build.gradle file

classpath 'com.android.tools.build:gradle:1.3.0'
查看更多
登录 后发表回答