SerializedName 是整个 Android 项目中未解析的引用,在构建时得到解析

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

在我的项目中的任何地方,我都看到注释 @SerializedName 未解析,即使我导入它也是如此:

import com.google.gson.annotations.SerializedName

我也有所有必要的 build.gradle 依赖项:

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'

我已多次同步项目文件并重新构建,但 Android Studio 一直以红色突出显示注释。

最奇怪的是,所有的东西都能完美地编译、构建和运行,但是所有的红色元素都会让项目的工作变得困难,我能错过什么吗?

只需升级到

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

您可以在 Github releases

上找到最新版本