android - 如何解决错误:无法合并dex

标签 android android-studio gradle android-gradle-plugin

我正在关注youtube上的教程,现在遇到了问题。当我同步构建文件时。构建完成没有任何错误,但是当我运行连接设备的应用程序时,出现以下错误

Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

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



但是当我删除线
 implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'

它工作正常,但是我需要这个库。那么我该如何解决。

我的应用程序build.gradle文件是

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.2"
    defaultConfig {
        applicationId "com.nepalpolice.cdp"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 2
        versionName "2.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

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

dependencies {
    implementation 'com.google.firebase:firebase-auth:11.0.4'
    implementation 'com.google.firebase:firebase-storage:11.0.4'
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:26.+'
    implementation 'com.android.support:support-v4:26.+'
    implementation 'com.android.support:cardview-v7:26.+'
    implementation 'com.google.firebase:firebase-messaging:11.0.4'
    implementation 'com.google.gms:google-services:3.1.0'
    implementation 'com.android.support:design:26.+'
    implementation 'de.hdodenhof:circleimageview:2.2.0'
    implementation 'com.android.support:multidex:1.0.1'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.6.+'
    implementation 'com.android.support:gridlayout-v7:26.+'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testCompile 'junit:junit:4.12'
    implementation 'com.google.android.gms:play-services-maps:11.0.4'


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


在我的lib文件夹中,我有 Volley jar文件。

我尝试了以下解决方案,但对我不起作用。



android {
defaultConfig {
multiDexEnabled是
}
}

并使用
compile 'com.android.support:multidex:1.0.1'

而且我删除了.gradle文件并清理和重建项目,但没有帮助。
我该如何解决?提前致谢。

最佳答案

这个问题发生在我身上,解决方案是发布图像裁剪器库。

就我和您而言,SDK是26,因此您需要编译2.5.1版本,而不是2.6.0版本:

implementation 'com.theartofdev.edmodo:android-image-cropper:2.5.1'

Android Image Cropper releases

关于android - 如何解决错误:无法合并dex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49346721/

相关文章:

android - 带有 RxJava2 的 Firebase.jobdispatcher 不能异步工作

java - Gradle 和 Maven 编译我的项目,但我收到 NoClassFoundError

gradle - 无论如何要在构建任务中执行特定任务吗?

java - 尝试从共享首选项中检索数据时我遗漏了什么

android - 带有换行文本的动态内容不起作用

android - 如何通知 Picasso 链接中的图像发生了变化?

javascript - java.lang.RuntimeException : Unable to start activity Component Info 错误

android - 无法解析符号 'AppCompatActivity'

java - 恢复用户图像后如何将其保存在 Drawable 中

java - Gradle项目中的IntelliJ IDEA编码问题