错误:'com.android.build.api.transform.TransformException:生成主dex列表时出错。'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误:'com.android.build.api.transform.TransformException:生成主dex列表时出错。'相关的知识,希望对你有一定的参考价值。

完全错误:

'任务执行失败':app:transformClassesWithMultidexlistForNoGPlayDebug'。 com.android.build.api.transform.TransformException:生成主dex列表时出错。

我成功地将Firebase集成到了我的应用中,但在尝试实施Firebase Analytics时遇到了问题。编译器开始解析我的google-services.json文件后会弹出此错误。有没有人对可能导致问题的原因有任何想法?这是我的项目级和应用级gradle文件:

项目级别

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext.kotlin_version = '1.3.0'

    repositories {
        google()
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {

        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

project.ext {
    supportVersion = "27.1.1"
    sdkVersion = 27
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用级

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

repositories {
    maven { url "https://dl.bintray.com/dasar/maven" }
    maven { url "https://s3.amazonaws.com/repo.commonsware.com" }
    maven { url "https://jitpack.io" }
    maven { url "https://maven.google.com" }
    mavenCentral()
    google()
    jcenter()
}


android {
    compileSdkVersion project.sdkVersion
    defaultConfig {
        applicationId "com.digitalnode.quickpick"
        minSdkVersion 19
        targetSdkVersion project.sdkVersion
        versionName "v1.1"
        versionCode 17
        vectorDrawables.useSupportLibrary = true

        multiDexEnabled true
    }

    lintOptions {
        disable 'MissingTranslation'
        disable 'ExtraTranslation'
        abortOnError false
    }

    dexOptions {
        jumboMode = true
    }

    // This is handled for you by the 2.0+ Gradle Plugin
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    signingConfigs {
        release
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            resValue "string", "app_name", "LeafPic"
            signingConfig signingConfigs.release
        }

        debug {
            applicationIdSuffix ".debug"
            resValue "string", "app_name", "QuickPic"
        }
    }

    flavorDimensions "default"

    productFlavors {
        noGPlay {
            dimension "default"
        }

        withGPlay {
            dimension "default"
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')

    //exifInterface
    implementation "com.android.support:exifinterface:$supportVersion"

    // google & support
    implementation "com.android.support:appcompat-v7:$supportVersion"
    implementation "com.android.support:cardview-v7:$supportVersion"
    implementation "com.android.support:recyclerview-v7:$supportVersion"
    implementation "com.android.support:design:$supportVersion"
    implementation "com.android.support:palette-v7:$supportVersion"
    implementation "com.android.support:customtabs:$supportVersion"
    implementation "com.android.support:support-v4:$supportVersion"

    //exo-player
    implementation 'com.google.android.exoplayer:exoplayer-core:2.6.0'
    implementation 'com.google.android.exoplayer:exoplayer-dash:2.6.0'
    implementation 'com.google.android.exoplayer:exoplayer-ui:2.6.0'
    implementation 'com.google.android.exoplayer:exoplayer-hls:2.6.0'
    implementation 'com.google.android.exoplayer:exoplayer-smoothstreaming:2.6.0'

    // utils
    implementation 'com.github.bumptech.glide:glide:4.7.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
    implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12'
    implementation 'com.github.Commit451:bypasses:1.1.0'
    implementation 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
    implementation 'com.drewnoakes:metadata-extractor:2.11.0'
    implementation "com.orhanobut:hawk:2.0.1"
    implementation 'com.commonsware.cwac:provider:0.4.3'

    // rxJava
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
    //it is recommended to keep the same version of rxAndroid
    implementation 'io.reactivex.rxjava2:rxjava:2.1.13'
//    implementation 'com.jakewharton.rxrelay2:rxrelay:2.0.0'

    // icons
    implementation 'com.mikepenz:iconics-core:3.0.3@aar'
    implementation "com.mikepenz:iconics-views:3.0.3@aar"
    implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
    implementation 'com.mikepenz:community-material-typeface:2.0.46.1@aar'
    implementation 'com.mikepenz:fontawesome-typeface:4.7.0.2@aar'

    // ui
    implementation 'uz.shift:colorpicker:0.5@aar'
    implementation 'com.github.jetradarmobile:desertplaceholder:1.1.1'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.github.yalantis:ucrop:2.2.2'
    implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
    implementation 'jp.wasabeef:recyclerview-animators:2.2.7'
    implementation 'com.github.HoraApps:Liz:-SNAPSHOT'
    implementation 'com.github.lzyzsd:circleprogress:1.2.1'

    // debug Only
    //debugCompile project(':inappstoragereader')
    implementation 'cat.ereza:customactivityoncrash:2.2.0'
    debugImplementation 'com.squareup.leakcanary:leakcanary-android:1.5.4'
    releaseImplementation 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.4'

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'

    // TODO check them out
    implementation 'com.turingtechnologies.materialscrollbar:lib:10.0.3'
    implementation 'de.psdev.licensesdialog:licensesdialog:1.8.3'

    implementation 'com.google.firebase:firebase-database:16.0.5'

    implementation 'com.google.android.gms:play-services-analytics:16.0.5'

    implementation 'com.google.firebase:firebase-core:16.0.5'
    implementation 'com.google.android.gms:play-services-ads:17.1.0'
}

Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()) {
    props.load(new FileInputStream(propFile))

    if (props != null && props.containsKey('STORE_FILE') && props.containsKey('KEY_ALIAS') && props.containsKey('PASSWORD')) {
        android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
        android.signingConfigs.release.storePassword = props['PASSWORD']
        android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
        android.signingConfigs.release.keyPassword = props['PASSWORD']
    } else {
        println 'signing.properties found but some entries are missing'
        android.buildTypes.release.signingConfig = null
    }
} else {
    println 'signing.properties not found'
    android.buildTypes.release.signingConfig = null
}

apply plugin: 'com.google.gms.google-services'
答案

尝试将play-service-ads降级为16.0.0

就我而言,它解决了这个问题。

以上是关于错误:'com.android.build.api.transform.TransformException:生成主dex列表时出错。'的主要内容,如果未能解决你的问题,请参考以下文章

react-native 中的导入 com.android.build.OutputFile 错误

Android Studio在build的时候出现transformClassesWithDexForDebug

错误:无法找到方法 'com.android.build.gradle.api.BaseVariant.getOutputs()Ljava/util/List;安卓工作室 3

如何修复错误 - 执行 com.android.build.gradle.internal.tasks.Workers$ActionFacade 时发生故障

com.android.build.transform.api.TransformException 与 android 谷歌播放服务

android开发里跳过的坑-AS导入NDK工程提示错误 No such property: sdkHandler for class: com.android.build.gradle.Librar