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.


当前回答

请看下面的图片去文件->项目设置->设置所有设置像图像和同步它将把所有最新的设置在你的项目。 如果您的项目导入成功,那么您必须这样做。因为它会导入所有的更新设置和gradle。

其他回答

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

我也遇到过同样的问题,当我创建一个新项目时,这种情况就会发生。

我所做的是:

检查SDK更新 然后是安卓工作室更新, 然后重新打开项目 打开andoridmanifest.xml 在android:标签中删除“_>”之间的空格并保存。

这对我很有用。

确保项目中有AndroidManifest.xml。

我导入的项目还没有manifest,所以Android Studio不会将其识别为Android项目。然后我在GIT中拉了这个项目,它下载了清单,但仍然不能工作。 然后我重新启动Android Studio,它说“框架检测到Android”。

确保你的项目配置为Android项目。

大多数情况下,此问题是由XML文件引起的,请查看XML文件,查找任何错误。

我用的是gradle 3.3.0。它是罪魁祸首。浪费了我生命中的6.5小时。Gradle 3.2.1删除了这个错误。

classpath 'com.android.tools.build:gradle:3.2.1'

问题解决后,改变gradle版本。详情历史可以在这里找到。