无法合并Dex - Android Studio 3.0.1 DexArchiveMergerException

3

我开始收到以下错误

错误:执行任务':app:transformDexArchiveWithExternalLibsDexMergerForDebug'失败。 java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: 无法合并 dex

当备份正在工作时,我尝试重置它,但是出现了相同的问题。

我尝试了所有解决方案,例如:

multiDexEnabled true

我尝试清理和重建项目,但没有成功。非常感谢您的帮助。

应用程序文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '27.0.2'
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
        resConfigs "auto"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
ext {
    supportLibraryVersion = '27.0.2'
    grpcVersion = '1.4.0'
}
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    testImplementation 'junit:junit:4.12'
//appcompat libraries
    compile 'com.android.support:design:27.0.2'
    compile 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:support-v4:27.1.0'

//butterknife
    compile 'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

//retrofit
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.scottyab:aes-crypto:0.0.4'
//circleimageview
    implementation 'de.hdodenhof:circleimageview:2.2.0'
//ZXing for barCode reader
    compile 'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    compile 'com.google.zxing:core:3.2.1'
//gson
    compile 'com.google.code.gson:gson:2.8.2'
//recyclerview and cardview
    implementation 'com.android.support:cardview-v7:27.0.2'
    compile 'com.android.support:recyclerview-v7:+'
//play-services
    compile 'com.google.android.gms:play-services-maps:11.8.0'




    implementation 'com.github.bumptech.glide:glide:4.3.1'
    implementation 'com.jaeger.statusbarutil:library:1.4.0'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile 'com.android.support:support-annotations:27.0.2'
    compile 'com.wang.avi:library:2.1.3'

}

项目文件
buildscript {

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

    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

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

我曾经查看了很多这里的其他问题和答案,但似乎找不到解决问题的方法:(


1
检查您的Gradle控制台。里面应该有更多详细信息,说明出了什么问题。这只是结束消息。请参阅此问题以获取示例。 - CommonsWare
我只是收到了错误信息DexArchiveMergerException: 无法合并dex。 - Ayman
请参考我在类似问题中的答案。同时,请在您的Gradle文件中将已弃用的compile替换为implementation - fdermishin
我已经尝试过这个解决方案,但没有任何改变。 - Ayman
我注意到你声明了supportLibraryVersion,但它在任何地方都没有被使用。例如,你可以将'com.android.support:design:27.0.2'替换为'com.android.support:design:${supportLibVersion}',并对所有的com.android.support库进行相同的操作。在你的问题中,支持库的不同版本是不一致的。 - fdermishin
我知道,但我这样做是为了确保问题不是来自这里。 - Ayman
2个回答

1

在尝试了stackoverflow上的所有解决方案后,我已经解决了问题。按照以下步骤进行:

  1. 将所有compile替换为implementation
  2. 将supportLibraryVersion设置为'27.0.2'
  3. 进行更改

'com.google.android.gms:play-services-maps:11.8.0'

'com.google.android.gms:play-services-maps:11.4.0'

  1. 删除所有未使用的库
  2. 删除项目中的.gradle文件夹
  3. 删除构建文件夹和gradle缓存
  4. 文件 -> 无效缓存/重启
  5. Build > 清理项目
  6. 添加

依赖关系 { implementation 'com.android.support:multidex:1.0.1'}

  1. 添加

android { defaultConfig { multiDexEnabled true } }

  1. 异步项目

最后,这是我的App文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.example"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}
ext {
    supportLibraryVersion = '27.0.2'

}
dependencies {

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

    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support:design:27.0.2'


//constraint
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'

//butterknife
    implementation  'com.jakewharton:butterknife:8.8.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
//avi:library
    implementation  'com.wang.avi:library:2.1.3'

//circleimageview
    implementation 'de.hdodenhof:circleimageview:2.2.0'

//retrofit2
    implementation 'com.squareup.retrofit2:retrofit:2.3.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.1.0'
    implementation 'com.squareup.okhttp3:okhttp:3.8.0'
    implementation 'com.jakewharton.retrofit:retrofit1-okhttp3-client:1.0.2'


//recyclerview and cardview
    implementation  'com.android.support:recyclerview-v7:27.0.2'
    implementation 'com.android.support:cardview-v7:27.0.2'


//ZXing for barCode reader
    implementation  'com.journeyapps:zxing-android-embedded:3.2.0@aar'
    implementation  'com.google.zxing:core:3.2.1'

//play-services
    implementation  'com.google.android.gms:play-services-maps:11.4.0'

//gson
    implementation  'com.google.code.gson:gson:2.8.2'
//statusbarutil
    implementation  'com.jaeger.statusbarutil:library:1.4.0'
//glide
    implementation 'com.github.bumptech.glide:glide:4.6.1'
    annotationProcessor 'com.github.bumptech.glide:compiler:4.6.1'
//multidex
    implementation 'com.android.support:multidex:1.0.1'
}

实际上,我不理解其中的真正原因,以及为什么突然发生了这种情况。

如果有人知道,请详细告诉我。

希望这可以帮助你。


这是由于分页库的原因。他们将一些类从库移动到本地recylerview-v7包中,所以我得到了相同的异常,我不得不更新支持库版本到“27.1.0”(最新版本),并且还要更新分页库到“alpha6”。 - AJay

-1

在浪费了几个小时的时间后,这对我有用。

只需按照以下步骤操作:

实现 >>> 注解处理器


2
请问您能详细说明一下吗?您是指在应用程序构建gradle文件中,将单词“Implementation”全部替换为“annotationProcessor”吗? - Atul
1
这是什么?这怎么算是一个答案呢? - Stealth Rabbi

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接