Android第三方库导致support版本冲突的问题

问题

当项目使用的support版本与第三方库使用的support版本不一致时会报错:

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

解决

在build.gradle中添加如下代码,让所有第三方包强制使用指定版本的support,当我们写库给别人用的时候,对于一些常用库,例如com.android.support,gson,最好使用compileOnly的依赖方式,避免冲突。

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

你可能感兴趣的:(Android)