开发中经常会遇到依赖冲突的问题:
Android dependency has different version for the compile and runtime
方法一,直接使用全局搜索。
如果版本都是在自己项目中,可以直接搜索到。修改即可。
如果冲突的依赖本身在一个包中,无法直接搜索到,需要使用方法二。
方法二,exclude
首先使用命令,查看依赖关系:
gradlew -q :app:dependencies
在结果中查找冲突的版本号
找到后就能定位到出问题的库。
把原来的
compile 'xxxxxxxxx'
修改为:
compile('xxxxxxxxxx', {
exclude group: 'com.android.support', module: 'design'
exclude group: 'com.android.support', module: 'recyclerview-v7'
})
方法三,统一设置
configurations.all {
resolutionStrategy.eachDependency { DependencyResolveDetails details ->
def requested = details.requested
if (requested.group == 'com.android.support') {
if (!requested.name.startsWith("multidex")) {
details.useVersion '25.4.0'
}
}
}
}
网友评论