origin
Our aar uses a certain function of Huawei and relies on a relatively new library. Huawei's base library version is 4.0.2. The third party uses Huawei push and the version is relatively old. Huawei's base library is 2.6.3. When accessing A conflict occurred during our aar.
You can view the dependency tree with the following command:
gradlew :app:dependencies
As you can see from the dependency tree, the two versions are inconsistent
Solution
1. Remove one of the base libraries
implementation 'com.huawei.android.hms:push:2.6.3.301', {
exclude group: 'com.huawei.android.hms',module:'base'
}
2. Unified version
configurations.all {
//循环一个个的依赖库
resolutionStrategy.eachDependency {
DependencyResolveDetails details ->
//获取当前循环到的依赖库
def requested = details.requested
// 查找要作处理的依赖的group名
if (requested.group == 'com.huawei.android.hms') {
// 查找要作处理的依赖的module名
if (requested.name.startsWith("base")) {
//这里指定需要统一的依赖版本
details.useVersion '4.0.3.302'
// details.useVersion '2.6.1.301'
}
}
}
}
Follow-up processing
Although the above method can solve the problem of base library conflict, due to the update of the base library, the third-party upper-layer push library dependency on the old version is not compatible with the updated base library. In the end, the third party can only update the Huawei push library.