Modified factory converter cannot access GsonConverterFactory

I included these dependencies in 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 through retrofitting:

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, this gives me this compile time error:

Error: (24, 17) error: the addConverterFactory method in the Builder class cannot be applied to the specified types; required: Factory found: Reason GsonConverterFactory: the actual argument GsonConverterFactory cannot be converted to Factory using method call conversion

How can i solve this? I followed the documentation. What's wrong?

+37
android gson retrofit
Oct 02 '15 at 7:10
source share
5 answers

Try using the same version for retrofitting and the gson converter is 2.0.0-beta2 . You use beta2 for modification and beta1 for converter.

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

Important Note!

Retrofitting will change the name of its package from version 2.0.0-beta3 . You should now use com.squareup.retrofit2 . Here is an example:

 compile 'com.squareup.retrofit2:retrofit:2.2.0' compile 'com.squareup.retrofit2:converter-gson:2.2.0' 
+107
Oct 02 '15 at 7:29
source share

With the latest version of Beta 2.0.3 you need to add:

 compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3' compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3' 

Be sure to map the version of the modified library to the version of gson converter.

+2
Jan 24 '16 at 19:35
source share

This is the last:

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

If you are using a beta version:

 compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.retrofit:adapter-rxjava:2.0.0-beta2' 
+2
Mar 21 '16 at 7:50
source share
  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 

If you get this error, the reason is the wrong dependency.

Add / change dependency in build.gradle application as file

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

make sure that the converter version 2.0.0-beta2 not 2.0.0-beta1 .

+1
Nov 04 '15 at 16:59
source share

In build.gradle (app) instead:

 implementation 'com.google.code.gson:gson:2.8.2' 

records:

 implementation 'com.squareup.retrofit2:converter-gson:2.3.0' 
0
Dec 10 '17 at 9:30
source share



All Articles