DexArchiveMergerException with Android Studio 3.0

感情迁移 提交于 2019-12-10 13:53:46

问题


Having compilation error with the following build.gradle details :

Top-Level build.gradle

buildscript {
repositories {
    google()
    jcenter()
    mavenCentral()
 }
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.0'
 }
}

allprojects {
    repositories {
        google()
        jcenter()
        mavenCentral()
        maven { url 'https://maven.google.com' }
    }
}

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

App-Level build.gradle

    apply plugin: 'com.android.application'

    android {
        compileSdkVersion 27
        defaultConfig {
            applicationId "com.abc"
            minSdkVersion 15
            targetSdkVersion 27
            versionCode 1
            versionName "1.0"
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
            multiDexEnabled true

            dataBinding {
                enabled true
            }

            dexOptions {
                javaMaxHeapSize "4g"
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }

        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }

    dependencies {
        implementation fileTree(dir: 'libs', include: ['*.jar'])
        testImplementation 'junit:junit:4.12'
        androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

        // Android
        implementation 'com.android.support:appcompat-v7:27.+'
        implementation 'com.android.support:support-v4:27.+'
        implementation 'com.android.support:support-annotations:27.+'

        // RxJava & RxAndroid
        implementation 'io.reactivex.rxjava2:rxandroid:2.+'
        implementation 'io.reactivex.rxjava2:rxjava:2.+'
        implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'


        //Glide for images
        implementation 'com.github.bumptech.glide:glide:4.+'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.+'

        // Retrofit : Network
        implementation 'com.squareup.retrofit2:retrofit:2.+'
        implementation 'com.squareup.retrofit2:converter-jackson:2.+'
        implementation 'com.google.code.gson:gson:2.+'

        // Multidex
        implementation 'com.android.support:multidex:1.+'

    }

This is the error

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. com.android.builder.dexing.DexArchiveMergerException: com.android.tools.r8.errors.CompilationError: Program type already present: android.support.v4.app.ActionBarDrawerToggle$DelegateProvider


回答1:


first, try this

  • clean your project
  • then rebuild

if the problem still remains

  • invalidate catch and restart from the file menu.

and at last if still problem remains try this

delete
\build
.idea
.gradle
app\build

then rebuild. hope this help;).




回答2:


This Error comes when we upgrade android studio or gradle version the solution is -

Please make sure that you are adding stable versions of firebase libraries and play services libraries.

I faced same problem when I switched to studio 3.1.2 and solved by checking all versions on these links and make sure if you are using the library modules must having same version as app.

https://firebase.google.com/support/release-notes/android#latest_sdk_versions

https://developers.google.com/android/guides/setup




回答3:


Resolved this issue by adding: implementation 'com.google.firebase:firebase-analytics:15.0.0'

So strange, However, as per firebase documentation, firebase-analytics included into firebase-core.




回答4:


You should not work with librairies that end with + . You should specify your version It will be :

        // Android
        implementation 'com.android.support:appcompat-v7:27.0.0'
        implementation 'com.android.support:support-v4:27.0.0'
        implementation 'com.android.support:support-
         annotations:27.0.0'

        // RxJava & RxAndroid
        implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
        implementation 'io.reactivex.rxjava2:rxjava:2.0.1'
        implementation 'com.tbruyelle.rxpermissions2:rxpermissions:0.9.4@aar'


        //Glide for images
        implementation 'com.github.bumptech.glide:glide:4.3.0'
        annotationProcessor 'com.github.bumptech.glide:compiler:4.3.0'

        // Retrofit : Network
        implementation 'com.squareup.retrofit2:retrofit:2.3.0'
        implementation 'com.squareup.retrofit2:converter-jackson:2.3.0'
        implementation 'com.google.code.gson:gson:2.8.1'

        // Multidex
        implementation 'com.android.support:multidex:1.0.1'


来源:https://stackoverflow.com/questions/47079710/dexarchivemergerexception-with-android-studio-3-0

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