Android Studio 说 "Cannot resolve method" 但项目构建正确

Android Studio says "Cannot resolve method" but the project builds correctly

我刚刚在工作中继承了一个相当大的 Android 代码库,在导入项目后我遇到了 Android/Android Studio 的一个令人困惑的问题:

打开一些项目文件,我看到一堆代码以红色突出显示(AS 报告 "Cannot resolve method XXXX"):

但项目构建得很好 (!):

有问题的方法不存在 AFAICS(我已经对它进行了全局搜索)但是,项目构建得很好。

我觉得问这个问题很傻,但是这里有人知道发生了什么事吗?

早些时候我遇到了同样的问题因为 Android Studio 将很多文件作为缓存并没有删除它们。当需要制作新文件时,这可能会造成麻烦,因此清除 caches will clear the old cache 可能会解决您的问题

转到 file menu 并单击 invalidate Caches / Restart

您是否没有右键单击 getPaymentsComponent() 并选择“转到”->“定义”以查看它会将您带到哪里?

嗯,原来这个项目正在使用 Lombok and those methods were auto-generated and Android Studio does not know how to how to handle them unless you install the Lombok plugin for Android Studio