第一次遇到这个问题是在使用Bmob后端云的时候,同时使用了bmob-sdk和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')    compile('com.squareup.retrofit2:adapter-rxjava:2.1.0')

不管是Clean还是Rebuild都是正常的,但是当我点击Run App的时候就会出现

Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: okhttp3/Address.class

亦或者

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

不过这两问题的本质都是一样的

询问了官方人员半天,原来是依赖包出现了相同类导致的冲突。解决的方案是将包相同的类去除,最后依赖的写法如下

    compile 'cn.bmob.android:bmob-sdk:3.5.1'    compile('com.squareup.retrofit2:retrofit:2.1.0')            { exclude group: 'com.squareup.okhttp3' }    compile('com.squareup.retrofit2:converter-gson:2.1.0')            { exclude group: 'com.google.code.gson'             exclude group: 'com.squareup.okhttp3' }    compile('com.squareup.retrofit2:adapter-rxjava:2.1.0')            { exclude group: 'io.reactivex'             exclude group: 'com.squareup.okhttp3' }

关于如何查找相同类,以及如何查找group,请看我的另一篇文章:

Android Studio中如何解决重复依赖导致的
app:transformClassesWithJarMergingForDebug

更多相关文章

  1. WebView 知识点
  2. Android(安卓)按压效果的工具类
  3. Dockerfile中使用sdkmanager安装Android(安卓)SDK自动接受licens
  4. Android(安卓)点击事件的写法
  5. Android关于Intent的思考:如何更好的启动一个Activity
  6. android javascript 调用activity
  7. network: Android(安卓)网络判断(wifi、3G与其他)
  8. Android中利用HttpURLConnection发送Post请求并添加参数的写法
  9. Android程序运行中动态加载Lib的方法(一)

随机推荐

  1. android studio 2.1.1 启动abd出错
  2. Android(安卓)studio 修改SDK路径
  3. Android(安卓)- 自定义Dialog内部透明,外
  4. Android默认USB为host模式
  5. Android(安卓)AsyncTask异步实现大文件下
  6. Android(安卓)SDK not found 的解决方案
  7. 【Android】glide:3.7.0->4.8.0 升级导入
  8. Settings中蓝牙连接流程
  9. Android(安卓)Notification的使用
  10. Looper源码探究—Android消息机制