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.


当前回答

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

Cannot resolve symbol 'default_web_client_id'

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

其他回答

我最近遇到了这个问题,清洁/构建等都没有解决它。我猜我在某个地方有一个问题,但不确定在哪里找到它(它是在清单,资源xml文件等?)

当出现问题时,您可以通过运行代码分析来找出问题所在。

从顶部的菜单中选择:

检查代码,使用'Default'配置文件扫描整个项目。

您的检查结果将包含一个名为“Android”的元素。在这里,您将获得导致资源和清单文件中出现问题的所有内容的列表。这些错误将打开生成的xml文件,并以红色显示任何错误。

我的确切问题是由于我使用基于flavor的清单文件,并且我意外地在flavor中的<application>标签内复制了一些权限。

更新:我确实有一个问题后,Android工作室仍然显示错误后修复,即使我现在可以构建和运行完美,而错误仍然存在。(我正在运行一个金丝雀构建,所以现在把它放下来)

我确实做了一个项目,而且成功了 但在此之前,请尝试检查清单中的包名称,重新构建并清理项目。如果问题没有解决,那就放弃你的项目

在我的情况下,我需要修复我的布局XML文件中的一些错误。没有指示文件包含错误的图标。然而,当我点击它们时,我注意到一些红线。修好后,找到了R。

上面的答案对我没有帮助。我最终意识到问题在于Android Studio中缺少“build”文件夹。我在项目“iml”文件中发现了一些行,不包括“build/*”。删除这些错误后,生成文件就出现了,错误就消失了。

你的代码被打乱了。答案相当简单。

点击构建->清洁项目。

这样应该可以了。

检查你的Android Studio版本。

我目前使用的是Android Studio 3.0.1。