【完美解决系列】duplicate entry: com/google/gson/annotations/Expose.class
来源:互联网 发布:java 迭代器实现原理 编辑:程序博客网 时间:2024/04/30 12:09
项目在引入Retrofit2时,运行项目时会报出以下错误:
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/annotations/Expose.class
仔细看了下错误报告,确定是gson这个库有重复导致的问题。
因为在项目的build.gradle中新加入
compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.squareup.retrofit2:converter-gson:2.1.0'
那么问题就确定了,因为引入了converter-gson:2.1.0所以出现的错误。
我们先来查找一下Expose.class这个类是有哪些重复使用的类库,在Android Studio中双击Shift键,打开搜索窗口,输入Expose.class。如图:
可以发现确实是有两个重复了,那么现在就来解决这个问题。
解决方法:
在项目中找到External Libraries里面的converter-gson-2.1.0。如图:
打开pom.xml,查看里面gson的groupId。如图:
找到gson的groupId后,我们就要把它去掉就可以了,现在就来把它去掉,步骤如下:
打开项目的build.gradle,把原来的compile ‘com.squareup.retrofit2:converter-gson:2.1.0’ 改成这样:
compile ('com.squareup.retrofit2:converter-gson:2.1.0'){ exclude group : 'com.google.code.gson' }
其中com.google.code.gson就是gson的groupId。
完成之后项目就可以正常运行了!
2 0
- 【完美解决系列】duplicate entry: com/google/gson/annotations/Expose.class
- java.util.zip.ZipException: duplicate entry: com/google/zxing/BarcodeFormat.class
- java.util.zip.ZipException: duplicate entry: com/ut/device/UTDevice.class问题的解决方式
- Android 解决java.util.zip.ZipException: duplicate entry: com/ta/utdid2/a/a.class
- Google Gson 字段过滤:@Expose
- 类似问题 duplicate entry: com/example/apputils/BuildConfig.class
- 【完美解决系列】duplicate definition of library class [android.net.http.SslError]
- com.google.gson.Gson;
- java.lang.NoClassDefFoundError: com/google/gson/Gson错误的解决
- java.lang.NoClassDefFoundError: com/google/gson/Gson错误的解决
- android gson解析Json,Could not find class 'com.google.gson.Gson'
- Could not find class 'com.google.gson.Gson', referenced from method com.itheima.redbaby.parser.Versi
- com.google.gson.JsonSyntaxException:com.google.gson.stream.MalformedJsonException的解决
- 异常处理TransformExcep: java.util.zip.ZipException: duplicate entry: com/ta/utdid2/device/UTDevice.class
- 解决Android使用GSON时报错 java.lang.NoClassDefFoundError: com.google.gson.Gson
- Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决
- Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决
- Android程序 依赖库引用Gson 报java.lang.NoClassDefFoundError: com/google/gson/Gson 解决
- 程序猿找工作黑名单
- UVA 202 循环小数
- Android基础控件—CardView
- 欢迎使用CSDN-markdown编辑器
- Unity 监听第一次进入播放状态的事件
- 【完美解决系列】duplicate entry: com/google/gson/annotations/Expose.class
- 你可能不知道 Google 最近的「小动作」
- maven本地库
- 两个整形数组,求其重复数字的个数
- SSL 1643——最小乘车费用
- 微信授权登陆介入第三方APP
- 15级软件三班15436325李佳姣oracle作业展示
- Hibernate4-11 二级缓存
- 另一种创建代码模版的方法