Search code examples
androidrestretrofitrx-javaretrofit2

RxJavaCallAdapterFactory cannot be converted to Factory


I'm trying to use Retrofit 2 and RxJava following the guide in this https://inthecheesefactory.com/blog/retrofit-2.0/en

In section "RxJava Integration with CallAdapter " explains how use RxJava with retrofit

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("http://api.nuuneoi.com/base/")
    .addConverterFactory(GsonConverterFactory.create())
    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
    .build();

However during compilation there is the following error:

Error:(63, 71) error: incompatible types: RxJavaCallAdapterFactory cannot be converted to Factory

How can I fix it? Thanks


Solution

  • Make sure you are using the same groupId and version for the main Retrofit dependency, the Gson converter dependency, and the RxJava adapter dependency.

    I'm guessing yours look something like this:

    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2'
    

    (Note that they use different groupIds and version numbers)

    They should all look the same like this:

    compile 'com.squareup.retrofit2:retrofit:2.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.0.2'
    compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'