retrofit convertor factory can not access GsonConverterFactory

AEMLoviji picture AEMLoviji · Oct 2, 2015 · Viewed 41.8k times · Source

I have included these dependencies to my project:

compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta1'

I have a class where I am going to access my api's via retrofit:

 public static  <S> S createService(Class<S> serviceClass, String baseUrl) {


        Retrofit builder = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .build();    

            RestAdapter adapter = builder.build();*/

        return  builder.create(serviceClass);
    }

And now, it gives me this compile time error :

Error:(24, 17) error: method addConverterFactory in class Builder cannot be applied to given types; required: Factory found: GsonConverterFactory reason: actual argument GsonConverterFactory cannot be converted to Factory by method invocation conversion

How can I solve this? I followed the documentation. What is wrong?

Answer

Ilya Tretyakov picture Ilya Tretyakov · Oct 2, 2015

Try to use same version for retrofit and converter-gson - 2.0.0-beta2. You are using beta2 for retrofit and beta1 for converter.

implementation 'com.squareup.retrofit:retrofit:2.0.0-beta2'
implementation 'com.squareup.retrofit:converter-gson:2.0.0-beta2'

Important note!

Retrofit change its package name since 2.0.0-beta3 version. Now you should use com.squareup.retrofit2. Here is example:

implementation 'com.squareup.retrofit2:retrofit:2.2.0'
implementation 'com.squareup.retrofit2:converter-gson:2.2.0'