异常信息:
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: com/google/gson/FieldNamingPolicy$5.class
看到错误:java.util.zip.ZipException: duplicate entry:时,一定是你的build.gradle 和 libs 中引入的 jar 包冲突导致的。确定了错误在哪就好办了,过滤掉重复的库呗。 这里既然提示是gson包重复:
打开app目录下的build.gradle,找到它的”android“闭包,在里面添加上以下代码
//去除重复依赖 configurations { all*.exclude module: 'gson' }
别忘了点Sync同步一下再打包apk
Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okio/AsyncTimeout$1.class
虽然还有错误,但是gson库错误解决了,说明有效,继续在之前位置添加过滤:
all*.exclude module: 'okio'
同步-打包-完美解决!
15:54 Generate Signed APK
APK(s) generated successfully.
Show in Explorer
参考stackoverflow上解决库冲突的问题:
https://stackoverflow.com/questions/26966843/java-util-zip-zipexception-duplicate-entry-during-packagealldebugclassesformult