Search code examples
javaandroidbuild.gradlebuild-dependenciesgradle-dependencies

How to resolve Unable to merge dex


When I was compile my application so I got below error like,

Error:Execution failed for task

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

I add the multiDexEnabled true in my app.build file but still getting same issue. how can I resolve this error.

Here below my app.build file

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"}

Solution

  • Use latest Dependencies for Lifecycle, including LiveData and ViewModel.

    Try this

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

    than Clean-Rebuild- Run your project