java - 无法合并Dex Android

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

Error Message

我得到的错误信息是:
错误:失败:生成失败,出现异常。

*What went wrong: Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Unable to merge 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
}

最佳答案

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

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'

关于java - 无法合并Dex Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53733187/

相关文章:

java - 如何更改 JCS cache.ccf 文件的路径?

android-studio - 安卓工作室 : always getting Failure [INSTALL_FAILED_DEXOPT]

java - Gradle 3.5 如何在 allproject 中从 archiveBaseName 设置 jar baseName

android - 为什么 Gradle 会运行两次测试?

gradle - Marklogic Spring Boot - 安装 Rest Endpoint

java - Android - 在没有 EditText 的情况下显示数字键盘

java - .drawLine 未绘制到 JTabbedPane (Java) 上

c# - 最长递增子序列的数量

android - Android Studio:在我的项目中进行更改后,是否需要在生成签名的apk之前手动进行项目?

java - android studio 使用或覆盖已弃用的 API