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工作室花栗鼠,最后我能够通过删除来解决这个问题

maven { url "https://jitpack.io" }

从设置。gradle我在回答这个问题,我认为这样做可能会帮助到一些人

其他回答

你们最近更新了SDK工具吗?启动android SDK管理器,确保你有最新的SDK工具,现在是独立于平台工具。当我第一次更新我的SDK管理器时,我也遇到了同样的问题,SDK构建工具包在安装/更新时没有出现,直到我关闭并重新打开SDK管理器。

我有未解决的R问题,因为相同的image.png文件在两个地方。一个在res>anim和相同的文件在res>drawable-hdpi。这导致R无法解决。 问题是我制作了一个启动画面图像,并反复将其从Moray图形目录直接移动到Android项目中。我一定是不小心把它扔进了res>anim文件夹。我通过从res>anim文件夹中删除重复的图像文件来解决这个问题,Android工作室纠正了自己。

在最新版本的Android Studio中,至少对我来说,如下作品:

“工具”->“Android”->“同步项目与Gradle文件”

在最新的Android Studio 3.1.3(2018年7月)中,“同步项目与Gradle文件”在主菜单栏中可用。

在我的情况下,在android studio版本0.8.9出现相同的错误(无法解析符号R)后,我所做的是去文件->项目结构,并将JDK的位置更改为我手动安装的oracle JDK。在我的例子中,在linux中,而不是预设的/usr/lib/jvm/java-7-oracle。我将其更改为/home/phvz/App/jdk1.8.0_20保存了设置,R符号问题立即得到了修复

只需清理你的项目和同步项目与Gradle文件。

问题会得到解决。