DexArchiveMergerException:合并 dex 档案时出错

DexArchiveMergerException: Error while merging dex archives

我收到 dex 合并错误。我正在使用 Android Studio 3.2.1。 T\here 还有一些模块。但我想这些是产生错误的文件。我尝试更新 Google Play 服务,但没有用。

我有两个模块 socket lib 和 iqsits lib。 iqsits 库添加到套接字库中。当我不在应用 gradle、运行 中添加它时,代码会提示我找不到 iqsits 包的错误。当我在应用程序中添加它时 gradle 代码给我 dex 合并错误。

项目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
}

应用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'

套接字库模块:

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 库模块

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

您不需要在应用程序的 build.gradle 中添加 iqsits_lib 依赖项,因为 socket_lib 已经在依赖项列表中包含它。如果你的主应用真的需要它改变

implementation project(path: ':iqsits_lib')

api project(path: ':iqsits_lib')

在 socket_lib 的 build.gradle 文件中

我遇到了合并错误,因为我的 multidex 没有启用。我在 build.gradle.

中将 multiDexEnabled 设置为 true 后它就消失了