DexArchiveBuilderException: Failed to process /xxx/.gradle/caches/transforms-1/files-1.1/play-services-location-11.2.2.aar

你离开我真会死。 提交于 2021-01-27 12:00:02

问题


When I try to compile my project I get this weird error:

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: Failed to process /Users/.../.gradle/caches/transforms-1/files-1.1/play-services-location-11.2.2.aar/f5b9886774f73d8b64cfd9701f91e8cc/jars/classes.jar

What I tried:

  1. Added multiDexEnabled true to app gradle.
  2. Added android.enableD8.desugaring = true and android.enableD8=true to gradle.properties
  3. Also removed .gradle folder and did rebuild + clean
  4. Also did the following: SDK manager -> Google play services -> updated. Rebuild + clean afterwards.

AS version: 3.1.4

App gradle file:

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 which was implemented has these dependencies:

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:


You are using all play-services with versions 15.x.x, and error is mentioning 11.2.2, this means that some other library is bringing in this dependency.

This type of error can be solved by following steps:

  1. run ./gradlew :app:dependencies command in terminal. (This will generate dependency hierarchy)
  2. Check for the dependency bringing in play-services-location dependency and exclude it from that dependency like below:

    compile ('<dependency-bringing-play-services-location>') {
      exclude  group:'com.google.android.gms'
    }
    
  3. Add play-services location dependency explicitly.



来源:https://stackoverflow.com/questions/52177847/dexarchivebuilderexception-failed-to-process-xxx-gradle-caches-transforms-1-f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!