Cannot resolve import com.google.api.client.json.gson.GsonFactory

I am trying to use a class GsonFactoryin my application:

StudentApi.Builder builder = new StudentApi.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), null);

but he says that cannot resolve symbol 'GsonFactory'

I have an import in my class

import com.google.api.client.json.gson.GsonFactory;

but gsoncould not resolve, so I tried Alt-Enter - Find jar on webbut could not find the library.

I have this in my dependency build.gradle:

dependencies {
   ...
   compile 'com.google.code.gson:gson:2.3'
   compile 'com.google.api-client:google-api-client-android:1.19.0'
}

I can confirm that this class exists .

+6
source share
4 answers

You need to use this library:

compile 'com.google.http-client:google-http-client-gson:1.19.0'
+18
source

GsonFactory from an older version.

JacksonFactory.getDefaultInstance().

: import com.google.api.client.json.jackson2.JacksonFactory;

+3

In your gradle.build you need to add:

compile ('com.google.http-client:google-http-client-gson:1.19.0') {
    exclude module: 'httpclient'
}

after

compile('com.google.http-client:google-http-client-android:1.19.0') {
    exclude(group: 'com.google.android', module: 'android')
}

After that you can use:

com.google.api.client.json.gson.GsonFactory()
0
source

this object is only in earlier versions of google-http-client, try 1.9.0 beta

compile 'com.google.http-client:google-http-client-android:1.9.0-beta'
0
source

Source: https://habr.com/ru/post/1584607/


All Articles