DexArchiveBuilderException:无法处理/xxx/.gradle/caches/transforms-1/files-1.1/play-services-location-11.2.2.aar

时间:2018-09-05 05:44:50

标签: android android-gradle

当我尝试编译我的项目时,出现这个奇怪的错误:

What went wrong:
Execution failed for task ':android:transformClassesWithDexBuilderForProdDevelopmentDebug'.
  

com.android.build.api.transform.TransformException:com.android.builder.dexing.DexArchiveBuilderException:com.android.builder.dexing.DexArchiveBuilderException:无法处理/Users/.../.gradle/caches/ transforms-1 / files-1.1 / play-services-location-11.2.2.aar / f5b9886774f73d8b64cfd9701f91e8cc / jars / classes.jar

我尝试过的事情:

  1. 已将multiDexEnabled true添加到应用gradle中。
  2. 在gradle.properties中添加了android.enableD8.desugaring = trueandroid.enableD8=true
  3. 还删除了.gradle文件夹并进行了重建+清理
  4. 还执行了以下操作:SDK管理器-> Google Play服务->已更新。重建并清理干净。

AS版本:3.1.4

应用gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion Android.compileSdkVersion
    buildToolsVersion Android.buildToolsVersion
    flavorDimensions "...", "type"

    defaultConfig {
        applicationId "xxx"
        versionName 'xxx'
        versionCode xxx
        minSdkVersion 21
        targetSdkVersion Android.targetSdkVersion //Android.targetSdkVersion holds value "27"
        multiDexEnabled true
    }

    dexOptions {
        javaMaxHeapSize "6g"
        preDexLibraries = true
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    productFlavors {           
        test {
            dimension "xxx"
            applicationIdSuffix '.xxx'
            versionNameSuffix 'x'
            manifestPlaceholders = [onesignal_app_id               : "",
                                    onesignal_google_project_number: ""]
        }
        production {
            dimension "xxx"
            manifestPlaceholders = [onesignal_app_id               : "",
                                    onesignal_google_project_number: ""]
        }
        development {
            dimension "type"
            resConfigs "xxhdpi"
        }
        normal {
            dimension "type"
        }
    }

    android.applicationVariants.all { variant ->
        variant.outputs.all {
            outputFileName = "..."
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
        exclude 'jsr305_annotations/Jsr305_annotations.gwt.xml'
        exclude 'build-data.properties'
        exclude 'error_prone/Annotations.gwt.xml'
        exclude 'third_party/java_src/error_prone/project/annotations/Annotations.gwt.xml'
        exclude 'third_party/java_src/error_prone/project/annotations/Google_internal.gwt.xml'
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    androidExtensions {
        experimental = true
    }
}

dependencies {
        implementation project(':projectxxx')
        implementation project(':tifCompanion')
        implementation fileTree(include: ['*.jar'], dir: 'libs')
        implementation files('libs/YouTubeAndroidPlayerApi.jar')
        kapt           "android.arch.lifecycle:compiler:1.1.1"
        implementation "android.arch.lifecycle:extensions:1.1.1"
        implementation "com.android.support.constraint:constraint-layout:1.1.0-beta5"
        kapt           "com.google.dagger:dagger-compiler:2.16"
        api            "com.android.support:leanback-v17:27.1.1"
        implementation "com.android.support:leanback-v17:27.1.1"
        api            "com.android.support:recommendation:27.1.1"
        implementation "com.android.support:recyclerview-v7:27.1.1"
        implementation "com.android.support:support-vector-drawable:27.1.1"
}
已实施的

projectxxx 具有以下依赖关系:

dependencies {
    api fileTree(include: ['*.jar'], dir: 'libs')
    api project(':JsonAPI') //https://github.com/faogustavo/JSONApi
    api            "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.2.61"
    implementation "com.onesignal:OneSignal:3.6.5"
    api            "com.google.android.gms:play-services-base:15.0.1"
    api            "com.google.android.gms:play-services-analytics:15.0.0"
    api            "com.android.support:support-annotations:27.1.1"
}

1 个答案:

答案 0 :(得分:4)

您正在使用所有版本为15.x.x的播放服务,并且错误中提到了11.2.2,这意味着其他一些库也引入了这种依赖性。

可以通过以下步骤解决此类错误:

  1. 在终端中运行./gradlew :app:dependencies命令。 (这将生成依赖关系层次结构)
  2. 检查引入了play-services-location依赖关系的依赖关系,并从该依赖关系中exclude如下所示:

    compile ('<dependency-bringing-play-services-location>') {
      exclude  group:'com.google.android.gms'
    }
    
  3. 显式添加播放服务位置依赖性。