首页 > 解决方案 > 构建项目时无法合并dex运行和重复条目

问题描述

这是我的 build.gradle

当我构建项目时出现此错误:

错误:任务“:app:transformClassesWithMultidexlistForDebug”执行失败。java.io.IOException: 无法写入 [D:\Dev\android\fruit\Fruit\app\build\intermediates\multi-dex\debug\componentClasses.jar] (无法读取 [C:\Users\bahrani .gradle\caches\transforms-1\files-1.1\support-core-ui-27.1.1.aar\7c83800d6960afec35a787899d518156\jars\classes.jar(;;;;;;**.class)] (重复的 zip 条目 [ classes.jar:android/support/design/widget/CoordinatorLayout$Behavior.class]))

当我运行项目时出现此错误:

错误:任务“:app:transformDexArchiveWithExternalLibsDexMergerForDebug”的执行失败。com.android.builder.dexing.DexArchiveMergerException:无法合并 dex

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion "27.0.2"
    defaultConfig {
        applicationId "pinuit.app.ir.fruit"
        minSdkVersion 17
        targetSdkVersion 27
        multiDexEnabled true
        versionCode 3
        versionName "1.7"
        manifestPlaceholders = [onesignal_app_id               : "222c377a-7695-433c-b6a0-4edd3cd79771",
                                // Project number pulled from dashboard, local value is ignored.
                                onesignal_google_project_number: "REMOTE"]
    }
    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    repositories {
        mavenCentral()
    }
}

dependencies {
    compile ('com.android.support.constraint:constraint-layout:1.0.2'){
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile ('com.android.support:support-v4:27.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile ('com.android.support:appcompat-v7:27.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile ('com.android.support:cardview-v7:27.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile ('com.android.support:recyclerview-v7:27.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    compile ('com.android.support:design:27.0.2') {
        exclude group: 'com.android.support', module:'support-v4'
    }
    implementation 'it.sephiroth.android.library.bottomnavigation:bottom-navigation:2.0.1-rc1'
    implementation 'com.wang.avi:library:2.1.3'
    implementation('com.squareup.retrofit2:retrofit:2.1.0') {
        exclude module: 'okhttp'
    }
    implementation 'com.squareup.okhttp3:okhttp:3.4.1'
    implementation 'com.squareup.retrofit2:converter-gson:+'
    implementation 'com.squareup.okhttp3:logging-interceptor:3.3.1'
    implementation 'com.github.bumptech.glide:glide:3.7.0'
    implementation 'jp.wasabeef:glide-transformations:2.0.0'
    implementation 'com.onesignal:OneSignal:[3.8.3, 3.99.99]'
    implementation 'com.google.firebase:firebase-core:12.0.1'
    implementation 'com.nineoldandroids:library:2.4.0'
    implementation 'com.daimajia.slider:library:1.1.5@aar'
}


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

标签: javaandroidandroid-studioandroid-gradle-pluginandroid-multidex

解决方案


我在尝试将 Unity3D 项目导入 Android Studio 时看到了类似的错误。首先,我将“编译”更改为“实现”,请参见下面的链接

https://stackoverflow.com/a/47304057/8634987

就我而言,我试图导入多个 .aar 文件,我发现此错误的解决方案是将所有 .aar 文件单独导入为库。希望这会有所帮助


推荐阅读