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

当使用maven导入依赖时,可能会出现不同的依赖包含了同一个jar,在编译期间不会报错。可一旦run app的时候,就会报

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: xxx.class
  • 1
  • 2

解决的方法是在引入依赖的时候把相同的jar去除掉

比方说,我同时引入了bmob和retrofit2的依赖

compile ('cn.bmob.android:bmob-sdk:3.5.1')
compile ('com.squareup.retrofit2:retrofit:2.1.0')
compile ('com.squareup.retrofit2:converter-gson:2.1.0')
  • 1
  • 2
  • 3

因为bmob底层也是通过引入okhttp来实现的,所以我报的错是:

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
  • 1
  • 2

这时候我们可以发现

 com/google/gson/annotations/Expose.class
  • 1

最后面有一个Expose.class
我们可以通过Search Everywhere去定位这个类(默认快捷键是双击shift)。

看,通过搜索的确发现了两个一模一样的类,而且来自不同的依赖,而重复的类库正是gson。此时再回想起我刚刚是不是添加过一个

compile ('com.squareup.retrofit2:converter-gson:2.1.0')
  • 1

好了,找到问题的根源的。那我们现在如何去除相同的类库呢,很简单:
在AS中,选择以project显示项目,找到最下面的External Libraries,然后继续找,找到相对应的类库:

如图依次点开之后发现了一个pom.xml,这里面就是关于这个jar的一些配置文件,点开之后长这个样子

往下找,发现了一个gson的引用

没错,这个就是导致报错的直接原因。复制里面groupId,到你的app的build.gradle里,找到那个依赖,添加{exclude group: 'com.google.code.gson'}
把这个groudId的引用去除掉。如下图所示

好了,到此问题就解决了,如果你有多个重复依赖的话,就按照本文所给出的方法,一个一个去重

transformClassesWithJarMergingForDebug的更多相关文章

  1. app:transformClassesWithJarMergingForDebug uplicate entry: android/support/v4/app/BackStackState$1.class

    .Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api. ...

  2. Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug

    这几天eclipse 项目迁移 android studio Error:Execution failed for task ':app:transformClassesWithJarMergingF ...

  3. 【踩坑速记】二次依赖?android studio编译运行各种踩坑解决方案,杜绝弯路,总有你想要的~

    这篇博客,只是把自己在开发中经常遇到的打包编译问题以及解决方案给大家稍微分享一下,不求吸睛,但求有用. 1.大家都知道我们常常会遇到dex超出方法数的问题,所以很多人都会采用android.suppo ...

  4. android常犯错误记录

    错误:Error:Error: Found item Attr/border_width more than one time 这个容易,属性相同了,按照提示查询一下找出来删了就行了,注意大小写很容易 ...

  5. Android开发各类常见错误解决方案

    本文属于个人平时项目开发过程遇到的一些问题,记录下来并总结解决方案,希望能帮到大家解决问题,有些问题的解决方案是在StackoverFlow上找到的,建议大家遇到问题多去上面找,基本上都能找到解决方案 ...

  6. android studio 各种问题

    1.dexDebug ExecException finished with non-zero exit value 2 全bug日志如下: (Error:Execution failed for t ...

  7. Android项目实战(三十九):Android集成Unity3D项目(图文详解)

    需求: Unity3D 一般用于做游戏 而且是跨平台的.原本设计是Android 应用端A(原生开发)进行一些业务处理,最后由A 打开Android 应用端B(Unity3D 游戏开发)进行游戏操作. ...

  8. Android studio 编译出现的问题记录

    1.app:transformClassesWithJarMergingForDebug'. Error:Execution failed for task ':app:transformClasse ...

  9. android常犯错误记录(一)

    错误:Error:Error: Found item Attr/border_width more than one time 这个容易,属性相同了,按照提示查询一下找出来删了就行了,注意大小写很容易 ...

随机推荐

  1. Qt实现探测当前有没有网络连接(Wi-Fi)——QNetworkConfigurationManager.isOnline()

    1.只需要探测当前有没有连上Wi-Fi(不用获取网络状态),可以调用<QNetworkConfigurationManager>类. QNetworkConfigurationManage ...

  2. IDEA中 @override报错的解决方法

    今天用IDEA导入一个java工程时,碰上一个问题,代码中所有@override处标红,并提示:@override不支持对接口的实现. 网上百度了一下发现, 原因是引用JDK5版本中存在小bug的问题 ...

  3. (笔记)linux设备驱动--LED驱动

    linux设备驱动--LED驱动 最近正在学习设备驱动开发,因此打算写一个系列博客,即是对自己学习的一个总结,也是对自己的一个督促,有不对,不足,需要改正的地方还望大家指出,而且希望结识志同道合的朋友 ...

  4. JUnit4 基本用法实例

    本教程介绍了在JUnit4中支持的基本注解. import org.junit.*; import static org.junit.Assert.*; import java.util.*; /** ...

  5. e799. 限制JSlider的数值在标记以内

    By default, the slider can take on any value from the minimum to the maximum. It is possible to conf ...

  6. 嵌入式开发之hi3516---GV7601 SPI通信问题

    http://blog.csdn.net/qq_29350001/article/details/52669964 http://blog.csdn.net/zqj6893/article/detai ...

  7. Mac terminal Javac

    Mac  terminal Javac Open the Terminal's vim , then write them: public class test{ public static void ...

  8. js 退后一步并刷新,window.history.back(-1);这个只能后退一步不能刷新,

    location.href=document.referrer; document.referrer是获取上一页的url

  9. jsTree 插件Ajax数据

    完整代码 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta ...

  10. php把数组、字符串 生成文件

    生成的代码 data/ss.php <?php return array ( ', ', ); php代码 $str = "<?php\nreturn \n"; $my ...