首页 > 解决方案 > 任务 ':app:mergeExtDexDebug' 执行失败。在实施 Firebase 消息传递时

问题描述

我遇到以下错误时遇到问题-> 在我的项目中实施实施 'com.google.firebase:firebase-messaging:19.0.1' 并开始给我以下错误。

com.android.build.api.transform.TransformException:java.lang.RuntimeException:java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:合并dex档案时出错:程序类型已经存在:androidx.versionedparcelable.NonParcelField

下面是我的 Gradle 文件。

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId 'XXXXXX'
        minSdkVersion 19//21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    productFlavors {
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    testImplementation 'junit:junit:4.12'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    implementation 'com.google.zxing:core:3.2.1'
    implementation 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    implementation 'com.microsoft.azure.android:azure-storage-android:2.0.0@aar'
    implementation 'com.googlecode.json-simple:json-simple:1.1'
    implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'

//    implementation 'com.google.firebase:firebase-core:17.0.0'
//    implementation 'com.mani:ThinDownloadManager:1.4.0'
    implementation 'com.mindorks.android:prdownloader:0.5.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//    implementation 'com.google.firebase:firebase-messaging:19.0.1'
    /*implementation 'com.android.support:multidex:1.0.3'
    implementation ('com.google.firebase:firebase-messaging:19.0.1') {
        exclude group: 'com.android.support'
    }*/
}
//apply plugin: 'com.google.gms.google-services'

标签: androidfirebase-cloud-messaging

解决方案


我通过在 Gradle 文件中添加 compileOptions 解决了这个问题

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

推荐阅读