RxJava2 和 Retrofit2 依赖时出现冲突问题
配置如下:
compile "com.squareup.okhttp3:okhttp:3.6.0"
compile "io.reactivex.rxjava2:rxjava:2.0.7"
compile "io.reactivex.rxjava2:rxandroid:2.0.1"
compile "com.squareup.retrofit2:retrofit:2.2.0"
compile "com.squareup.retrofit2:converter-gson:2.2.0"
compile "com.squareup.retrofit2:adapter-rxjava:2.2.0"
然后在编译运行的时候报错了:
原因是使用了rxjava2, compile"io.reactivex.rxjava2:rxjava:2.0.7"
但是retrofit2一开始是基于rxjava开发的适配器即adapter-rxjava,
这个适配器只适合rxjava,如果想使用rxjava2就得使用adapter-rxjava2适配器
这个适配器有两个
一个是retrofit2官方设计的(上线不久),
另外一个就是jakewharton大神弄出来的retrofit2-rxjava2-adapter适配器。
所以把compile "com.squareup.retrofit2:adapter-rxjava:2.2.0"
改成 compile "com.squareup.retrofit2:adapter-rxjava2:2.2.0"
就可以了。
注意:如果设置了
build.addCallAdapterFactory(RxJavaCallAdapterFactory.create())//这里的RxJavaCallAdapterFactory要换成RxJava2CallAdapterFactory