Alex Petev
Alex Petev

Reputation: 489

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

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?

Upvotes: 18

Views: 7753

Answers (2)

vksssd
vksssd

Reputation: 67

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'

Upvotes: 1

ronzano
ronzano

Reputation: 382

Just upgrade to

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

You can find the latest version on Github releases

Upvotes: 27

Related Questions