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?
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:
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
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.
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.
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With