Search code examples
androidexceptionmergearchivedex

DexArchiveMergerException: Error while merging dex archives


I am getting dex merging error. I am using Android Studio 3.2.1. T\here are some more modules. But I guess these are the files from where error is generating. I tried to update Google Play services it didn't work.

I have two modules socket lib and iqsits lib. The iqsits lib is added in socket lib. When I don't add this in app gradle, running the code gives me error for iqsits package not found. When I add it in app gradle code gives me dex merging error.

project gradle:

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
        classpath 'com.google.gms:google-services:3.2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

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

app gradle:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    buildToolsVersion '27.0.3'
    defaultConfig {
        applicationId "com.intmilli.imobile"
        vectorDrawables.useSupportLibrary = true
        minSdkVersion 17
        targetSdkVersion 27
        versionCode 1
        versionName "1.0.0.0"
        multiDexEnabled true
    }
    buildTypes {
        /* release {
            debuggable false
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }*/
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    useLibrary 'org.apache.http.legacy'
    sourceSets { main { assets.srcDirs = ['src/main/assets', 'app/assets/', 'assets/'] } }

    dexOptions {
        javaMaxHeapSize "4g"
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'META-INF/services/javax.annotation.processing.Processor'
    }

    lintOptions {
        disable 'InvalidPackage'
    }
}


repositories {
    maven { url "https://jitpack.io" }
}

ext {
    supportLibraryVersion = '27.1.1'
    playServicesVersion = '11.0.4'
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    // External project jar files
    implementation files('libs/mail.jar')
    implementation files('libs/activation.jar')
    implementation files('libs/additional.jar')
    //implementation files('libs/gson-2.3.1.jar')
    implementation project(':MPChartLib')
    implementation project(':iqsits_lib')
    implementation project(':socket_lib')
    implementation 'com.google.code.gson:gson:2.8.2'

    //Android support libs
    implementation "com.android.support:design:$supportLibraryVersion"
    implementation "com.android.support:cardview-v7:$supportLibraryVersion"
    implementation "com.android.support:recyclerview-v7:$supportLibraryVersion"
    implementation "com.android.support:appcompat-v7:$supportLibraryVersion"
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    //Google play services libs
    implementation "com.google.android.gms:play-services-gcm:$playServicesVersion"
    implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
    //External service libs
    implementation 'com.mcxiaoke.volley:library:1.0.19'
    implementation 'com.fasterxml.jackson.core:jackson-core:2.7.3'
    implementation 'com.fasterxml.jackson.core:jackson-annotations:2.7.3'
    implementation 'com.fasterxml.jackson.core:jackson-databind:2.7.3'
    //Custom views libs
    implementation 'com.astuetz:pagerslidingtabstrip:1.0.1'
    implementation 'com.balysv:material-ripple:1.0.2'
    implementation 'com.jakewharton.rxbinding2:rxbinding-appcompat-v7:2.0.0'
    implementation 'de.hdodenhof:circleimageview:1.2.1'
    //implementation 'com.qhutch.bottomsheetlayout:bottomsheetlayout:0.1.3'
    implementation 'com.github.castorflex.smoothprogressbar:library-circular:1.0.0'
    //firebase libraries
    implementation "com.google.firebase:firebase-auth:$playServicesVersion"
    implementation "com.google.firebase:firebase-config:$playServicesVersion"
    implementation 'org.aviran.cookiebar2:cookiebar2:1.0.9'
    implementation 'me.biubiubiu.justifytext:library:1.1'

    //imobile
    implementation 'com.github.ybq:Android-SpinKit:1.1.0'

    implementation 'uk.co.chrisjenx:calligraphy:2.3.0'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:multidex:1.0.1'
}
apply plugin: 'com.google.gms.google-services'

socket libs module:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion '27.0.3'


    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation group: 'org.apache.mina', name: 'mina-core', version: '2.0.4'

    implementation project(path: ':iqsits_lib')
}

iqsits lib module

apply plugin: 'com.android.library'

android {
    compileSdkVersion 28
    buildToolsVersion '27.0.3'

    defaultConfig {
        minSdkVersion 17
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'org.java-websocket:Java-WebSocket:1.3.0'
}

Solution

  • You don't need to add iqsits_lib dependency in your app's build.gradle because socket_lib already has it in the dependency list. If your main app really needs it change

    implementation project(path: ':iqsits_lib')
    

    to

    api project(path: ':iqsits_lib')
    

    inside socket_lib's build.gradle file