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.


当前回答

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

其他回答

我发现在大型项目中,自动生成的R.java大于2.55MB (Intellij的默认限制),这导致文件生成但无法解析。要解决这个问题,只需提高极限:

在Android Studio帮助->编辑自定义属性…

接受并添加以下内容: idea.max.intellisense.filesize = 3000 (3000或任何大于R文件大小的值)

最后,重启你的Android Studio!

更改最新的SDK版本,这对我来说是工作

1.单击文件,然后单击项目结构 2.然后选择app 然后点击确定,这对我有用。

在我的例子中,当我试图从另一个包调用R时,出现了这个错误。导入R包解决了我的问题。

import com.mtdaps.yourapp.R;

这些在Ubuntu 12.04上都不适用。我必须做到以下几点:

sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1

在那之后,我遵循了这个线程中的其他一些建议,做了Build ->清洁项目,一切都很好。

第一个解决方案

Rebuild your gradle or invalidate/restart your system.

第二个解决方案

delete .gradle and .idea folder from your android project. So you can solve "R" problem

并且还消除了红线错误发生的任何原因你得到。