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工作室修复了这个问题。

其他回答

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

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

只需从根包中导入R符号

import rootpackage.R;

没有重建,同步或其他事情…

我今天升级了gradle版本和gradle插件版本的最新版本,它为我工作。

之后,同步项目与gradle文件。

如果你在.xml文件上有任何错误,无论你做什么,你都无法修复这个问题。我建议

-首先,检查XML文件以查找任何错误和

-秒查找事件日志什么Android工作室捕捉到的错误,它会告诉你哪个文件和错误在哪里。

这就是我解决R问题的方法

这是最近删除的xml造成的 在Android Studio中,从这些xml中清除你的项目,选择: Build ->清洁项目