Moustafa EL-Saghier
Moustafa EL-Saghier

Reputation: 1931

Gson library imports not exist

I just tried to upgrade my dependencies but, the import classes are missing now. I think something broke in this upgraded version.

These are my current Gradle dependencies:

implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.6'

And following classes are missing at compilation time Gson and GsonBuilder

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

Can anyone help me, please?

Hint: There are no new imports to load.

Upvotes: 1

Views: 1705

Answers (3)

Daniel
Daniel

Reputation: 189

This problem seems to happen sometimes when upgrading the IDE, its a Sync Issue

Simple solution:

In build.gradle

implementation 'com.google.code.gson:gson:2.8.9' [is the version you want, but doesn't work]

Rollback & Sync, Rollforward & Sync

implementation 'com.google.code.gson:gson:2.8.8' --> Sync --> implementation 'com.google.code.gson:gson:2.8.9' --> Sync

Should work if your lucky :) If not, invalidate caches, reload and roll back and forth again.

Upvotes: 0

Tako
Tako

Reputation: 3444

I also see the same problem gson 2.8.6

But it seems to be resolved in 2.8.7 gson 2.8.7

Upvotes: 1

RenatoIvancic
RenatoIvancic

Reputation: 2092

Nothing has changed from version 2.8.5 to 2.8.6 in regards to com.google.code.gson:gson.

Below is the content of the com.google.code.gson:gson:2.8.6 version of the jar. You can see Gson and GsonBuilder classes are present. I don't know which IDE are you using, but you should check how dependencies are resolved in your project. You might use gradlew dependencies command and check the dependency tree. Be sure com.google.code.gson:gson:2.8.6 is properly resolved.

Part of the result of running gradle dependencies command

compileClasspath - Compile classpath for source set 'main'.
+--- com.squareup.retrofit2:converter-gson:2.9.0
|    +--- com.squareup.retrofit2:retrofit:2.9.0
|    |    \--- com.squareup.okhttp3:okhttp:3.14.9
|    |         \--- com.squareup.okio:okio:1.17.2
|    \--- com.google.code.gson:gson:2.8.5 -> 2.8.6
\--- com.google.code.gson:gson:2.8.6

This is a screenshot of dependencies resolved in IntelliJ for com.google.code.gson:gson:2.8.6, you can clearly see classes are present in correct package:

enter image description here

Upvotes: 0

Related Questions