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.


当前回答

考虑以下IDE功能:

用gradle文件同步项目 Build ->清洁项目 Build ->重建项目 File ->使缓存失效


我的简单解决方案是:

Check that there is no error line in the dependencies of the build.gradle of the app or in all the resource files in the /res directory; where some common errors are when the attribute values are left without references when using: "@string/.." "@style/.." Make sure you are not getting an error of the type Android resource linking failed when the project is rebuilt. Open the file that contains the line with the error Cannot resolve symbol 'R' Scrolling to the last line of the class with said error line Click on a position to the right of the closing key } of the class

通过这种方式,IDE警告对话框将执行r类的导入。

GL

其他回答

显然,在我的例子中,这个问题通过在结尾添加一个“*”得到了解决

import android.R.*;

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

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

您只需要检查Xml文件。 如果出现错误,则无法解决此错误。 只需解决xml错误,然后尝试。

OR

清理你的项目从构建->清洁

在OS X和Android Studio 0.2.13上,我在com上做了“跳转到声明”。<项目>。在我的活动之一。当我回到活动文件时,所有的警告都消失了。

编辑:在此工作之前,您需要构建当前的构建变体。

我在可绘制资源中添加了一些图像,其中一个图像被命名为“super.jpg”,这是一个原因。

重命名图像并在此之后将项目与gradle文件同步修复了错误。