SerializedName is an unresolved reference throughout Android project, gets resolve when building

Viewed 4095

Everywhere in my project I see that the annotation @SerializedName is unresolved, even though I import it:

import com.google.gson.annotations.SerializedName

I also have all the necessary build.gradle dependencies:

implementation "com.squareup.retrofit2:retrofit:2.9.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.6.2"
implementation "com.squareup.retrofit2:converter-gson:2.9.0"

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

I've synced project files and rebuilt multiple times, but the annotation keeps getting highlighted in red by Android Studio.

The oddest part is that everything compiles, builds and works perfectly, but having all the red elements makes working on the project difficult, what could I be missing?

2 Answers

Just upgrade to

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

You can find the latest version on Github releases

retrofit and gson should have same same version to work well inorder to work well in build.gradle(:app)

implementation 'com.squareup.retrofit2:retrofit:2.9.1' implementation 'com.google.code.gson:gson:2.9.1' implementation 'com.squareup.retrofit2:converter-gson:2.9.1'

Related