You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

引入com.googlecode.json-simple后出现Duplicate class类重复错误如何解决?

问题原因
  • 你的Gradle配置中首先存在两处重复的JUnit依赖声明:testImplementation 'junit:junit:4.+'与testImplementation 'junit:junit:4.12',同时androidTestImplementation 'androidx.test.ext:junit:4.10'内部也集成了hamcrest相关类
  • com.googlecode.json-simple:json-simple:1.1.1会传递依赖org.hamcrest:hamcrest-core:1.1,和JUnit携带的hamcrest类产生重合,因此只有在引入json-simple时才会触发类重复报错
解决方案

按以下步骤修改即可解决冲突:

  1. 清理重复的JUnit依赖:删除其中一条testImplementation的JUnit声明,建议统一保留稳定版本,比如testImplementation 'junit:junit:4.13.2'
  2. 引入json-simple时排除自带的hamcrest依赖,将原有的json-simple依赖语句替换为:
implementation ('com.googlecode.json-simple:json-simple:1.1.1') {
    exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
  1. 同步Gradle配置后重新构建项目即可正常编译

如果不需要使用json-simple,也可以直接替换为Gson、Jackson等其他无冲突的JSON处理库,同样可以解决该问题。

内容的提问来源于stack exchange,提问作者remov

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 17:57:03