项目经常会引用第三用依赖库,比如主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"
}