Search code examples
androidgradlegsonretrofit2

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?


Solution

  • Just upgrade to

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

    You can find the latest version on Github releases