Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 839
Alex Petev Avatar asked Jun 14 '21 08:06

Alex Petev


People also ask

Why does my Android application say unresolved reference?

When you’re writing code for Android application and Kotlin, you may frequently encounter a static error from your IDE saying unresolved reference for a specific keyword or variable. For example, you can produce the error by calling a custom function that you haven’t defined in your code yet: Or when you assign a variable without declaring them:

How to fix the unresolved reference drawable error?

Below are the steps to replicate the Unresolved reference: drawable error and to fix the error. Below is the default boilerplate code that will be generated on clicking Finish Add a logo inside drawable folder. Then implement the logic to display image inside the Greeting composable

What is unresolved reference error in Kotlin?

To conclude, the unresolved reference error happens when Kotlin has no idea what the keyword you’re typing in the file points to. It may be a function, a variable, or another construct of the language that you’ve yet to declare in the code.

Is it possible to use kotlinx-serialization-runtime-common as runtime dependency?

If your Shared module is pure common, try using kotlinx-serialization-runtime-common as runtime dependency artifact id Sorry, something went wrong. My Shared module uses common, android and iOS.


Video Answer


2 Answers

Just upgrade to

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

You can find the latest version on Github releases

like image 80
ronzano Avatar answered Oct 21 '22 23:10

ronzano


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'

like image 1
vksssd Avatar answered Oct 22 '22 01:10

vksssd