Android 多module依赖版本冲突解决
当项目使用模块化开发的时候,尤其是迭代开发,新的module的使用的更高版本的第三方依赖库,当app 引用module 的时候,可能引发依赖版本的代码冲突,这个该怎么解决呢?
比如:
我创建了一个module :common
common 里面有编写了一个GlideUtils 需要引用
implementation "com.github.bumptech.glide:glide:4.12.0"
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'
这里使用的glide是 4.0+ 版本
但是app 老代码之前依赖了了3.0+ 的glide
implementation "com.github.bumptech.glide:glide:3.7.0"
有大量的旧代码:
Glide.with(mContext)
.load("")
.into(new SimpleTarget<GlideDrawable>() {
@Override
public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> glideAnimation) {
}
});
在4.0 中回调是这样的:
Glide.with(this).load("").into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(@NonNull Drawable resource, @Nullable Transition<?
super Drawable> transition) {
}
});
如果一个个的改不现实,最好的办法就是在app 中使用3.0 而不使用common 中的4.0 版本glide
解决办法
在app 的依赖引用加上这样的注明,去除相关依赖:
implementation (project(':common')){
exclude group: 'com.github.bumptech.glide'
}
需要注意的是
project(':common')
外层要加一个 ()