如何解决Unable to merge dex

How to resolve Unable to merge dex

当我编译我的应用程序时出现以下错误,例如

Error:Execution failed for task

':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

我在 app.build 文件中添加了 multiDexEnabled true,但仍然遇到同样的问题。我该如何解决这个错误。

下面是我的 app.build 文件

apply plugin: 'com.android.application'
 android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.example.rutunjay.retrofit_example"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}}

dependencies {

testImplementation 'junit:junit:4.12'
compile 'android.arch.lifecycle:runtime:1.0.0-alpha1'
compile 'android.arch.lifecycle:extensions:1.0.0-alpha1'
annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha1"}

使用最新的Dependencies for Lifecycle, including LiveData and ViewModel.

试试这个

implementation 'android.arch.lifecycle:runtime:1.1.1'
implementation 'android.arch.lifecycle:extensions:1.1.1'
annotationProcessor "android.arch.lifecycle:compiler:1.1.1"

Clean-Rebuild- Run你的项目