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.


当前回答

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

其他回答

类型1:关闭项目并删除项目中的.gradle文件 然后重建项目 类型2:如果类型1不起作用,那就把它拿回来 project9Zip文件),然后删除项目。然后提取 压缩项目,只是导入提取的项目,它将工作 很好,因为这对我很管用。

这让我很头疼。在我的案例中,在Android Studio中配置“谷歌播放服务”后出现了错误(安装+ build。gradle配置)。这反过来需要minsdk > 7,但错误是非常不清楚的(实际上一个抱怨这只出现为“信息”)。总之. .在清单文件和构建中将minsdk更改为8。Gradle文件和重建项目,错误消失了。

所以. .关于这一点,如果我可以概括的话,你可能在你的清单文件或其他配置文件中有一些问题,这阻碍了正确的构建。试着仔细查看错误报告,甚至是标题为“info”的消息,以寻找任何关于它可能是什么的提示……

我也有这个问题。简单的“gradlew clean”和“gradlew build”就成功了。


点击Build->Clean Project,将执行gradle Clean

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

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

对我有用的是:

创建一个新项目。 发现R在工作! 比较了所有的配置。 在gradle文件中发现了差异: 同步,它又工作了!