gradle 使用 exclude 解决jar包冲突

项目经常会引用第三用依赖库,比如主module有glide,引用的第三方库也引用glide,glide版本不一致,就容易冲突。

解决方法:

1. 查看冲突的jar包;一眼能看出来的跳到第二步; 遇到隐藏比较深的就比较难受了,肉眼完全看不出来,此时打开AS的terminal控制台输入以下命令查看:

gradlew -q app:dependencies 查看依赖树;

比如: 

报错信息:

Duplicate class androidx.dynamicanimation.animation.DynamicAnimation$OnAnimationUpdateListener found in modules classes.jar (androidx.dynamicanimation:dynamicanimation:1.0.0) and classes.jar (dynamicanimation-1.1.0-alpha04.aar)
Duplicate class androidx.dynamicanimation.animation.DynamicAnimation$ViewProperty found in modules classes.jar (androidx.dynamicanimation:dynamicanimation:1.0.0) and classes.jar (dynamicanimation-1.1.0-alpha04.aar)

打开AS的terminal控制台输入:gradlew -q app:dependencies 

+--- com.airbnb.android:lottie:3.3.1
|    +--- androidx.appcompat:appcompat:1.0.0 -> 1.3.0-rc01 (*)
|    \--- com.squareup.okio:okio:1.17.4
+--- com.google.android.material:material:1.3.0
|    +--- androidx.annotation:annotation:1.0.1 -> 1.2.0
|    +--- androidx.appcompat:appcompat:1.1.0 -> 1.3.0-rc01 (*)
|    +--- androidx.cardview:cardview:1.0.0
|    |    \--- androidx.annotation:annotation:1.0.0 -> 1.2.0
|    +--- androidx.coordinatorlayout:coordinatorlayout:1.1.0 (*)
|    +--- androidx.constraintlayout:constraintlayout:2.0.1 -> 2.1.0-beta01 (*)
|    +--- androidx.core:core:1.2.0 -> 1.6.0-alpha01 (*)
|    +--- androidx.dynamicanimation:dynamicanimation:1.0.0
|    |    +--- androidx.core:core:1.0.0 -> 1.6.0-alpha01 (*)
|    |    +--- androidx.collection:collection:1.0.0 -> 1.1.0 (*)
|    |    \--- androidx.legacy:legacy-support-core-utils:1.0.0 (*)
|    +--- androidx.annotation:annotation-experimental:1.0.0
|    +--- androidx.fragment:fragment:1.0.0 -> 1.3.2 (*)
|    +--- androidx.lifecycle:lifecycle-runtime:2.0.0 -> 2.3.1 (*)
|    +--- androidx.recyclerview:recyclerview:1.0.0 -> 1.2.0-rc01 (*)

右键find, 输入关键字dynamicanimation:dynamicanimation,可以看到com.google.android.material:material:1.3.0 引入了它;

2.主module的build.gradle使用exclude过滤掉;

implementation ('com.google.android.material:material:1.3.0') {
    exclude group: "androidx.dynamicanimation", module: "dynamicanimation"
}

原文地址

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值