dzboot02
dzboot02

Reputation: 2979

Generating APK problems: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

I have Android Studio on Windows 10, and I have this error whenever I try to debug my app:

enter image description here

This is my Project level build.gradle

buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3"
        classpath 'com.google.gms:google-services:3.1.1'
    }
}

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

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

And this is Module level build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '26.0.3'
    defaultConfig {
        applicationId "com.dzboot.salha.client"
        minSdkVersion 16
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.home_fragment.runner.AndroidJUnitRunner"
    }
    dexOptions {
        preDexLibraries = false
    }
    buildTypes {
        release {
            shrinkResources true
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        checkReleaseBuilds false
        abortOnError false
    }
    defaultConfig {
        javaCompileOptions {
            annotationProcessorOptions {
                includeCompileClasspath = true
            }
        }
    }
}

dependencies {
    implementation('com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.6.2') {
        transitive = true
    }

    def firebaseVersion = '11.8.0'
    def playservicesVersion = '11.8.0'
    def androidSupportVersion = '27.1.0'

    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.6.2'
    implementation "com.google.firebase:firebase-auth:$firebaseVersion"
    implementation "com.google.firebase:firebase-messaging:$firebaseVersion"
    implementation 'com.github.TheBrownArrow:PermissionManager:1.0.0'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'gun0912.ted:tedbottompicker:1.0.12'
    implementation 'com.akexorcist:googledirectionlibrary:1.0.5'
    implementation 'com.loopj.android:android-async-http:1.4.9'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation "com.google.android.gms:play-services-maps:$playservicesVersion"
    implementation "com.google.android.gms:play-services-location:$playservicesVersion"
    implementation "com.google.android.gms:play-services-places:$playservicesVersion"
    implementation "com.google.android.gms:play-services-base:$playservicesVersion"
    implementation "com.google.firebase:firebase-database:$firebaseVersion"
    implementation 'com.google.code.gson:gson:2.8.1'
    implementation 'com.android.support:multidex:1.0.3'

    implementation "com.android.support:cardview-v7:$androidSupportVersion"
    implementation "com.android.support:appcompat-v7:$androidSupportVersion"
    implementation "com.android.support:design:$androidSupportVersion"
}

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

I tried cleaning project, invalidating cache and restarting, also tried running: gradlew -q dependancies to see any conflicts, this is what I get:

Configuration 'compile' in project ':app' is deprecated. Use 'implementation' instead.

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring project ':app'.

    Failed to notify project evaluation listener. Could not initialize class com.android.sdklib.repository.AndroidSdkHandler

  • Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 1s

And my gradle-wrapper.proprieties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip

EDIT Referring to the comment below concerning multiple Java version. I did have two Java versions, I kept Java 8u161 and uninstalled the other, and I changed the location of Java in my Project Structure settings, but I still have the same problem.

I am really lost guys, please help me!

Upvotes: 0

Views: 705

Answers (1)

dzboot02
dzboot02

Reputation: 2979

Thanks to @shadowsheep, I solved the problem. I added this in app level build.gradle

dependencies {
    /.../
    implementation "android.arch.lifecycle:extensions:1.1.0"
}

Running the application in the emulator worked fine, but I had a lot of warnings and an error while trying to generate the apk.

Then I had to remove this from the same file to make it work:

buildTypes {
    release {
        shrinkResources true
        minifyEnabled true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}

If anyone know how to make it work with ProGuard, please come forward :)

Upvotes: 1

Related Questions