终极方法, 解决Duplicate class 开头的报错内容全过程详解 - Duplicate class com.github.promeg.tinypinyin

只要你是 Duplicate 开头的报错, 一定要看一下这个解决方法
只要你是 Duplicate 开头的报错, 一定要看一下这个解决方法
只要你是 Duplicate 开头的报错, 一定要看一下这个解决方法

今天改东西, 在没有新增任何jar包和aar包以及依赖的时候, Android studio 突然莫名其妙的报错了,

报错内容如下:
Duplicate class com.github.promeg.tinypinyin.android.asset.lexicons.AndroidAssetDict found in modules classes.jar (com.github.promeg.tinypinyin:tinypinyin-android-asset-lexicons:2.0.3) and classes.jar (com.github.promeg:tinypinyin-android-asset-lexicons:2.0.3)
Duplicate class com.github.promeg.tinypinyin.android.asset.lexicons.BuildConfig found in modules classes.jar (com.github.promeg.tinypinyin:tinypinyin-android-asset-lexicons:2.0.3) and classes.jar (com.github.promeg:tinypinyin-android-asset-lexicons:2.0.3)
Duplicate class com.github.promeg.tinypinyin.lexicons.android.cncity.BuildConfig found in modules classes.jar (com.github.promeg.tinypinyin:tinypinyin-lexicons-android-cncity:2.0.3) and classes.jar (com.github.promeg:tinypinyin-lexicons-android-cncity:2.0.3)
Duplicate class com.github.promeg.tinypinyin.lexicons.android.cncity.CnCityDict found in modules classes.jar (com.github.promeg.tinypinyin:tinypinyin-lexicons-android-cncity:2.0.3) and classes.jar (com.github.promeg:tinypinyin-lexicons-android-cncity:2.0.3)

Go to the documentation to learn how to Fix dependency resolution errors.

截图献上:
在这里插入图片描述
在这里插入图片描述

现在我们开始解决这个问题
现在我们开始解决这个问题
现在我们开始解决这个问题

  1. 打开Android studio的命令面板Terminal控制台, 输入以下内容并回车

./gradlew app:dependencies

如图:
在这里插入图片描述

  1. Android studio 会查找所有依赖并输出日志到Terminal控制台, 如图(内容太多无法全部截图, 只截图部分内容以供查看):
    在这里插入图片描述

  2. 找到刚才报错的日志内容, 复制报错内容中的括号里的依赖内容, 在刚才的Terminal控制台中搜索, 如图
    在这里插入图片描述
    搜索内容如图:

    找到了, 是 me.yokeyword:indexablerecyclerview:1.3.0 这个依赖引用了 com.github.promeg.tinypinyin:tinypinyin-android-asset-lexicons:2.0.3 导致的程序报错, 我们先找到 me.yokeyword:indexablerecyclerview:1.3.0 的所在位置

  3. 全局搜索 me.yokeyword:indexablerecyclerview:1.3.0 , 如图
    在这里插入图片描述

  4. 找到后, 删除或者替换即可, 我这里直接删除了, 我看了一下, 项目里压根就没有用这个库
    在这里插入图片描述

  5. 再次运行, 错误解决了, 程序已经运行到手机上了

在这里插入图片描述

总结: 他大爷的, 项目里没有用到pinyin这个库, 找遍了所有文件和文件夹都没有找到和pinyin相关的任何内容, 突然就报错了, 看有人说是库的内容重复了, 也就是类重复了, 但是只有这一个库引用了pinyin的这个库, 真是坑爹呀, 一天又结束了…

  • 14
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
出现"duplicate class androidx.annotation.animres found in modules annotation-1.5."的错误提示,意味着在Android项目的依赖中,出现了重复的类。 这个错误通常是由于项目中引入的两个或多个库依赖中,都出现了相同的类名的冲突所引起的。 解决这个问题的方法有以下几种: 1. 通过检查项目的依赖关系,找到重复的库依赖并移除其中一个。可以在项目的build.gradle文件中查找引入的库依赖,然后逐个排查可能存在重复的库依赖。 例如,可能出现的情况是: dependencies { implementation 'com.android.support:appcompat-v7:28.0.0' implementation 'androidx.appcompat:appcompat:1.0.0' //其他依赖项 } 由于上述两个依赖库都包含了相同的类名androidx.annotation.animres,因此会出现冲突错误。需要选择其中一个库依赖,并将其移除,以消除冲突。 2. 更新库依赖版本。有时,重复类冲突是由于库依赖版本不一致造成的。可以尝试升级或降级某个库依赖的版本,以解决冲突。 3. 使用gradle的exclude功能,排除重复的类。可以在库依赖的声明中添加exclude操作,排除重复的类。 例如: implementation('com.android.support:appcompat-v7:28.0.0') { exclude group: 'androidx.annotation' } 在这种情况下,将排除appcompat-v7库中的androidx.annotation包,以解决冲突。 总之,通过检查项目的依赖关系,移除重复的库依赖、更新库依赖版本或使用gradle的exclude功能,可以解决"duplicate class"错误导致的冲突问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值