In every instance in all of my classes where I reference R.id.something, the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from Eclipse. I am using what I believe to be the most recent version of Android Studio and the project was created with Android Studio and worked without any "cannot resolve R" problems. I would like to know what causes this if anyone knows.


当前回答

Build ->清理项目或重建项目 或 File -> Invalidate cache / Restart…->失效并重启

其他回答

这个问题似乎有很多原因。最近,我添加了一个名为NewActivity的活动来测试。这创建了一个名为res/menu/new.xml的文件,gradle不喜欢这个名字,因为new是一个保留字。

gradlew戒毒

or

“工具”->“Android”->“同步项目与Gradle文件”

这些绝对是值得尝试的好方法,但是在运行这些命令之前,您可能需要解决一些其他问题。

Build ->清理项目或重建项目 或 File -> Invalidate cache / Restart…->失效并重启

清洁,重建和“缓存删除”不会帮助我,更新Android工作室修复了这个问题。

我已经做了其他答案中提到的所有步骤,但它仍然没有得到解决。我正在使用android工作室花栗鼠,最后我能够通过删除来解决这个问题

maven { url "https://jitpack.io" }

从设置。gradle我在回答这个问题,我认为这样做可能会帮助到一些人

在我的情况下,原因是有一些图像在res文件夹名称包含一个大写字母..

只要用小写字母重新命名就可以了