duplicate entry: com/google/gson/FieldNamingPolicy$5.class
duplicate entry: com/google/gson/FieldNamingPolicy$5.class
1.问题说明
在使用gson中的时候,出现如下错误:
Execution failed for task ‘:app:transformClassesWithJarMergingForRelease’.
com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/FieldNamingPolicy$5.class
原因是导入的包有所重复,有可能是jar包和modules中的重复,我这里就是这种情况,在多次重新编译时,还有可能会产生下面的问题:
What went wrong:
Execution failed for task ‘:app:transformClassesWithMultidexlistForDebug’.
java.io.IOException: Can’t write [/Users/jk/WebStormProject/MYProjectf/android/app/build/intermediates/multi-dex/debug/componentClasses.jar] (Can’t read [/Users/jk/.gradle/caches/modules-2/files-2.1/com.google.code.gson/gson/2.8.5/f645ed69d595b24d4cf8b3fbb64cc505bede8829/gson-2.8.5.jar(;;;;;;**.class)] (Duplicate zip entry [gson-2.8.5.jar:com/google/gson/annotations/SerializedName.class]))
但是解决思路都是一样的,就是移除掉多余的gson包,再解决的过程中,我查了很多文章,但是,其中包括这篇文章duplicate entry: com/google/gson/annotations/Expose.class报错解决 ,上面这种用法可能对于之前版本的有效,在我使用时,会提示如下错误:
A problem occurred evaluating project ':app'. > Could not find method com.google.code.gson:gson:2.8.5() for arguments [build_c79q8dkccdz0f2ed8wg8e6062$_run_closure2$_closure18@4fd99d88] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
所以没有很好的解决掉我的问题,在我的版本中,我使用了如下方法进行移除多余的gson.
2 .解决方案:
在github上找到了一个解决方案:
1.issue-1
2.issue-2
在路径
android/app/build.gradle android中添加如下代码:
configurations{ all*.exclude module:'gson' //Remove duplicate dependencies: gson }
同样的,在移除
support-v4的时候,也可以使用下面的方法
configurations{ all*.exclude module:'support-v4' //Remove duplicate dependencies: support-v4 }
3. 下面也是一种做法
使用 Multidex support library 开启 Multidex 功能
步骤 1:更改 build.grade
defaultConfig { ... // Enabling multidex support. multiDexEnabled true }
编辑日期:2018-10-28
感谢omkn对我问题的解答
- Java Class Life Cycle - Beginning
- Javascript定义类(class)的三种方法
- java.lang.ClassCastException android.view.AbsSavedState
- 【转载】java class运行时热替换(hotswap)
- Scala case class
- 第02课 02 JS中级课程-addClass,removeClass-2
- SQL SERVER 2005 流览多维数据集时出现没有注册类别(异常来自:HRESULT:0x80040154 (REGDB_E_CLASSNOTREG))的错误
- org.objectweb.asm.ClassWriter.<init>(I)V异常
- Python面向对象的基础知识:类Class,对象(Object),实例(Instance)
- CJJ专用ASP类库中的某个class
- java.lang.UnsupportedClassVersionError Bad version number in .class file
- Django——基于类的视图(class-based view)
- 黑马程序员——java环境变量path和classpath
- this.class.getResource 、this.classLoader.getResource 和ClassLoader.systemResource的区别
- dx.bat转换jar 包(java 1.8)出现 unsupported class file version 52.0 …while parsing
- 前端小知识点--class命名规范
- VC6中关于bool __cdecl std::isdigit(_E,const class std::locale &)' : expects 2 arguments 的错误
- 《A Simple IOCP Server/Client Class》整改
- 配置class PATH
- Jquery.addClass始终无效原因分析