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.


当前回答

只需进入Android Top菜单列表。点击构建菜单,在构建下点击重建项目。

其他回答

你们最近更新了SDK工具吗?启动android SDK管理器,确保你有最新的SDK工具,现在是独立于平台工具。当我第一次更新我的SDK管理器时,我也遇到了同样的问题,SDK构建工具包在安装/更新时没有出现,直到我关闭并重新打开SDK管理器。

有一件事每次都对我有效:

转到——> build。你项目的gradle (Module: app)文件——>做一点改变(例如:把一个<空格>放在某个地方,然后把它移回来)——>然后android studio会要求你同步你的gradle文件——>在文件的右上角——>选择“立即同步”。

在同步完成后,它将解决大多数情况下的问题。

我有未解决的R问题,因为相同的image.png文件在两个地方。一个在res>anim和相同的文件在res>drawable-hdpi。这导致R无法解决。 问题是我制作了一个启动画面图像,并反复将其从Moray图形目录直接移动到Android项目中。我一定是不小心把它扔进了res>anim文件夹。我通过从res>anim文件夹中删除重复的图像文件来解决这个问题,Android工作室纠正了自己。

我也有同样的问题。我尝试了上面提到的大多数其他人,即Gradle同步,验证缓存和重新启动,清洁和重建项目…重新启动android studio,仍然有同样的问题…

这是我的问题,我认为其他人可能也有同样的问题。我在新创建的布局文件的名称上有空格…而不是file_example.xml我是文件_example.xml **(注意文件和_之间的空格)**当你试图找到这个布局文件的引用时,你会遇到一个错误。

我建议您查看您刚刚创建的最新布局文件,稍微重构名称,然后将您的R.layout更改为activity/fragment中的新文件—> 然后清理..重建项目,项目将编译没有任何错误。至少对我来说,这是解决问题的办法。

这不是错误。 如果你有错误 关闭项目。 然后打开项目 在此之后,您可以得到一个错误

Cannot resolve symbol 'default_web_client_id'

可以通过在sting值中插入Web客户端ID来解决