Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Am trying to use the GsonFactory class in my app:

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

but it says cannot resolve symbol 'GsonFactory'

I have the import in my class

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

but gson couldn't be resolved so I tried Alt-Enter - Find jar on web but the library couldn't be found.

I have this in my build.gradle dependencies:

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 does exist.

like image 646
Ojonugwa Jude Ochalifu Avatar asked Apr 25 '15 07:04

Ojonugwa Jude Ochalifu


3 Answers

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 doing so, you will be able to use:

com.google.api.client.json.gson.GsonFactory()
like image 29
Guildenstern70 Avatar answered Oct 27 '22 20:10

Guildenstern70


You need to use this library:

compile 'com.google.http-client:google-http-client-gson:1.19.0'
like image 133
BrendanBenting Avatar answered Oct 27 '22 18:10

BrendanBenting


GsonFactory is from the older version.

Now, you should use JacksonFactory.getDefaultInstance() instead.

Import it like this import com.google.api.client.json.jackson2.JacksonFactory;

like image 42
Azamat Bekkhozha Avatar answered Oct 27 '22 19:10

Azamat Bekkhozha