无法解决**无法合并dex错误**

Cannot solve ** Unable to merge dex error **

我知道这个问题已经被问过很多次了,我搜索过它们但无法解决我的问题。我添加了
multiDexEnabled true

还有

implementation 'com.android.support:multidex:1.0.3'

正如一些答案所建议的那样,但无法解决。任何人都可以帮助我,因为自从出现这个问题后,我就卡住了。

错误是“错误:任务执行失败:app:transformDexArchiveWithExternalLibsDexMergerForDebug”。

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

我的 build.gradle 文件是

apply plugin: 'com.android.application'

 android {
  compileSdkVersion 27
   defaultConfig {
    applicationId "com.flashcardapp"
    minSdkVersion 21
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
    testInstrumentationRunner 
    "android.support.test.runner.AndroidJUnitRunner"


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

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

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:support-annotations:27.1.1'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
implementation 'com.android.support:multidex:1.0.3'

//pin edittext library
implementation 'com.alimuzaffar.lib:pinentryedittext:1.3.1'

// glide
implementation 'com.github.bumptech.glide:glide:3.7.0'

//amazon aws
implementation 'com.amazonaws:aws-android-sdk-core:2.6.22'
implementation 'com.amazonaws:aws-android-sdk-cognito:2.2.13'
implementation 'com.amazonaws:aws-android-sdk-s3:2.6.22'
implementation 'com.amazonaws:aws-android-sdk-ddb:2.6.22'
implementation 'com.amazonaws:aws-android-sdk-ddb-mapper:2.6.22'
implementation ('com.amazonaws:aws-android-sdk-mobile-client:2.6.+@aar') { transitive = true }
implementation 'com.amazonaws:aws-java-sdk-s3:1.11.323'

testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'

}

您可以通过将 MaxHeapSize 添加到 gradle 文件中来尝试。

android {
...
dexOptions {
    javaMaxHeapSize "4g"
   }
}

希望以上内容能帮助您解决问题。

在 app/build 中执行此操作。gradle:

android {
    defaultConfig {
       multiDexEnabled true
    }
}

然后清理并重建您的项目。希望这有效:)

我按照 Redman 的建议通过删除未使用的库然后清理并重建项目解决了这个问题。