无法合并Dex Android

时间:2018-12-11 22:18:23

标签: java android-studio gradle android-gradle

Error Message

给出的错误消息: 错误:失败:构建失败并出现异常。

  

*出了什么问题:任务执行失败   ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'。

     
    

java.lang.RuntimeException:com.android.builder.dexing.DexArchiveMergerException:无法合并     dex

  

我曾尝试将multidex设置为true,并按照类似博文中的说明从应用程序gradle中更改和删除行,但是构建仍然失败。

apply plugin: 'com.android.application'

android {
    compileSdkVersion 'android-P'
    defaultConfig {
        applicationId "com.dheia.crypton"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

   }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-annotations:26.1.0'
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'
    //adding library for search
    implementation 'com.github.mirrajabi:search-dialog:1.1'
    compile 'com.android.support:support-annotations:27.1.1'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.github.AnyChart:AnyChart-Android:1.0.6'
    added dependency to Anycharts Git
}

1 个答案:

答案 0 :(得分:0)

您的某些依赖项隐式依赖于不同版本的支持库,它们是:

implementation 'com.github.mirrajabi:search-dialog:1.1'
implementation 'com.github.AnyChart:AnyChart-Android:1.0.6'

特别是使用以下支持库的搜索对话框:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:recyclerview-v7:25.3.1'

因此,您需要使用以下代码排除它们:

implementation ('com.github.mirrajabi:search-dialog:1.1') {
   exclude group: 'com.android.support'
   exclude module: 'appcompat-v7'
   exclude module: 'recyclerview-v7'
}

然后,您需要为所有依赖项提供相同版本的支持库。因此,请更改以下内容:

compile 'com.android.support:support-annotations:27.1.1'

implementation 'com.android.support:support-annotations:26.1.0'