android.support库的依赖冲突

做项目时用到android-support-v4的依赖包,运行时出现以下错误

Duplicate class androidx.annotation.AnimRes found in modules annotation-1.0.0.jar (androidx.annotation:annotation:1.0.0) and jetified-android-support-v4.jar (android-support-v4.jar)
Duplicate class androidx.annotation.AnimatorRes found in modules annotation-1.0.0.jar (androidx.annotation:annotation:1.0.0) and jetified-android-support-v4.jar (android-support-v4.jar)
Duplicate class androidx.annotation.AnyRes found in modules annotation-1.0.0.jar (androidx.annotation:annotation:1.0.0) and jetified-android-support-v4.jar (android-support-v4.jar)....

原因是android-support-v4的依赖包和androidx库冲突,androidx在默认情况下在编译时添加

此时可以用到2种方法

  1. 将你用到android-support-v4的地方改为androidx,如我的问题是AndroidManifest里的
    android:name="android.support.v4.content.FileProvider"改为
    android:name="androidx.core.content.FileProvider"
  2. 将androidx库禁用,在gradle.properties文件中将
    android.useAndroidX=true 和 android.enableJetifier=true改为false

有什么问题希望大家可以指点一下

你可能感兴趣的:(学习日记)