关于集成Bmob遇到的坑

来源:互联网 发布:js遍历json对象数组 编辑:程序博客网 时间:2024/04/30 18:12

1.因为我的项目用到的开源组件比较多,所以遇到了不少坑,在这里给大家分享一下。

2.首先我列举报的错误:

         Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lrx/android/BuildConfig;

       Error:Execution failed for task ':app:transformClassesWithDexForDebug'.> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lokhttp3/Address;

    Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lrx/android/BuildConfig;

3.上面的错误是我分别遇到的,大家也看明白了是包冲突,当时我就懵逼了,那么多包从哪里找起,于是我用最笨的方法解决:

这样挨个的找,不过还是解决了,后面又报:

二、问题分析:

1、 rxandroid:1.1.5 在 dependencies 并没有添加1.1.5版本(注意工程中添加的是rxandroid:2.0.1),此lib从何而来?

答案是肯定的,显然在dependencies 添加的其他libs中有使用到 rxandroid:1.1.5 版本的。

2、多余的rxandroid:1.1.5 是被那个lib使用到的呢?如何知道呢?

在文件目录下或 Android Studio的 Terminal下敲

gradlew -q app:dependencies

便有各个libs引用关系的输出:

+--- com.squareup.okhttp3:okhttp:3.6.0|    \--- com.squareup.okio:okio:1.11.0+--- org.greenrobot:eventbus:3.0.0+--- com.jakewharton:butterknife:8.5.1|    +--- com.jakewharton:butterknife-annotations:8.5.1|    |    \--- com.android.support:support-annotations:25.1.0 -> 25.1.1|    +--- com.android.support:support-annotations:25.1.0 -> 25.1.1|    \--- com.android.support:support-compat:25.1.0 -> 25.1.1 (*)+--- io.reactivex.rxjava2:rxandroid:2.0.1|    \--- io.reactivex.rxjava2:rxjava:2.0.1|         \--- org.reactivestreams:reactive-streams:1.0.0+--- io.reactivex.rxjava2:rxjava:2.0.1 (*)+--- com.google.code.gson:gson:2.7+--- com.squareup.retrofit2:retrofit:2.1.0|    \--- com.squareup.okhttp3:okhttp:3.3.0 -> 3.6.0 (*)+--- com.squareup.retrofit2:converter-gson:2.1.0|    +--- com.squareup.retrofit2:retrofit:2.1.0 (*)|    \--- com.google.code.gson:gson:2.7\--- com.squareup.retrofit2:adapter-rxjava:2.1.0     +--- com.squareup.retrofit2:retrofit:2.1.0 (*)     \--- io.reactivex:rxjava:1.1.5
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

通过各个libs引用的关系图,就可以清楚的看出:

adapter-rxjava:2.1.0 中使用的是 io.reactivex:rxjava:1.1.5

三、问题解决:

1、知道是那个libs中和rxandroid:1.1.5 ,问题就好解决了,直接

exclude 问题解决!

compile (‘com.squareup.retrofit2:adapter-rxjava:2.1.0’){ 
exclude module: ‘rxjava’ 
}

 希望对于第一次集成Bmob的同学有帮助