- 看依赖树
gradlew :app:dependencies
- 依赖传递:默认依赖传递是true,transitive= true。比如A依赖了B,B依赖了C,C依赖了D。则A会依赖BCD
配置全局的依赖不传递
configurations.all {
transitive = false
}
配置单个依赖的依赖不传递
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
transitive = false
}
- 同种依赖方式的依赖,多个版本,相同的库会以最高版本为准
compile "com.tencent.module:1.0"
compile "com.tencent.module:2.0"
因为同样是以compile的方式依赖,所以会以最高的com.tencent.module:2.0为准
- 不同依赖方式的依赖,多个版本会有冲突,解决方案
1. force强制指定版本
全局指定某个库的版本
configurations.all {
resolutionStrategy {
force 'org.hamcrest:hamcrest-core:1.3'
}
}
单独指定
compile("com.tencent.module:1.0"){
force "com.tencent.module:1.0"
}
2. exclude排除某个版本的库不加入编译
全局排除某个库的版本
configurations {
all*.exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
也可以只指定group
configurations {
all*.exclude group: 'com.android.support.test'
}
指定排除某个依赖的版本库
androidTestCompile('com.android.support.test.espresso:espresso-core:2.1') {
exclude group: 'org.hamcrest'
}