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.


当前回答

我在androidmanifest中有android:textAllCaps = "false",这对R文件造成了严重破坏。我删除了,一切正常。我认为目标sdk设置得不够高。

其他回答

我正面临一个错误“无法解析符号R” java文件中的R显示为红色。我已经解出来了。

不保存任何大写字母的图像 像ABC.png。 首先删除映像或重命名它。 清洁项目 重建项目

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

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

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

我也遇到了这个问题,我用这种方法解决了它。 首先进入Gradle,点击clean。 其次,单击Build。

确保不要从android studio清洁

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

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

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

当我导入google服务时,我就遇到了这个问题。json文件来实现分析。我已经在xml文件夹中有global_tracker.xml文件。在构建过程中,合并来自google-services的内容。Json文件,错误开始发生。

删除google -services后,该错误得到解决。json文件。