Android third-party library causes support version conflict solution

question

Upgrade the compileSdk version to 26, and at the same time modify the version of the support package, an error is reported

all com.android.support libraries must use the exact same version specification(mixing versions can lead to runtime crashes)

That is to say, there is a conflict between the imported third-party library and the current compiled version.

solve

Generally, the solution to this problem is to add at the specified dependency of exclude group: 'com.android.support'the conflicting library, so that the conflicting library can not be included in the compilation, such as

compile('xx.xxx.xxxxx:xxxxx:1.5.5') {
    exclude group: 'com.android.support'
}

But the problem is that I don't know which third-party library conflicts, it's impossible to check one by one, right?

At this time, you only need to add the following code to the gradle file to force all third-party packages to use the specified version of the support package:

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

And when writing a third-party library for others to use, the dependency on the support package is changed to provided (or compileOnly, gradle3.0), so that the support will not be
packaged, which is convenient for those who use it.

More about gradle3.0

After gradle is upgraded to 3.0, there are more dependencies. The most significant change is that the ones that have been used before compilecan be replaced with implementation, such as

implementation 'xx.xxx.xxxxx:xxxxx::1.5.5'

implementationIt refers to the introduction of dependencies. The things introduced by this third-party package cannot be used in the project. It tastes like an interface and shields the internal implementation. Can speed up gradle compilation.

The same debugcompile releasecompileis debug implementation release implementation.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325672266&siteId=291194637
Recommended