且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

即使启用 multidex 后也无法在 Android Studio 3.0.1 中合并 DEX

更新时间:2023-11-17 18:56:46

这不是 multidex 问题...这是依赖合并冲突问题.

This isn't a multidex problem...it's a dependency merge conflict issue.

从外观上看,您的一个依赖项对 CoordinatorLayout 具有子依赖项,但指定了与您正在使用的版本不同的版本.您可以通过在 build.gradle 中使用 resolutionStrategy 来定义要使用的支持库的版本来解决此问题.

By the looks of it one of your dependencies has a sub-dependency on CoordinatorLayout but has specified a different version from the one which you are using. You can fix this by using a resolutionStrategy in your build.gradle to define the version of the support library to use.

首先创建一个变量来定义你的支持库版本:

First make a variable to define your support library version:

ext {
    supportLibVersion = "26.1.0"
}

然后更新你的依赖以使用这个变量而不是硬编码的值(注意双引号):

Then update your dependences to use this variable rather than the hard coded value (note the double quotes):

implementation "com.android.support:appcompat-v7:${supportLibVersion}"
implementation "com.android.support:design:${supportLibVersion}"

然后你可以添加一个 resolutionStrategy 到你的 build.gradle:

Then you can add a resolutionStrategy to your build.gradle:

configurations.all {
    resolutionStrategy.eachDependency { details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion "${supportLibVersion}"
            }
        }
    }
}

这样做是要求 Gradle 忽略依赖项中指定的版本号并使用您的版本.

What this does is ask Gradle to ignore the version number specified in with the dependency and use your version.