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.


当前回答

我发现在大型项目中,自动生成的R.java大于2.55MB (Intellij的默认限制),这导致文件生成但无法解析。要解决这个问题,只需提高极限:

在Android Studio帮助->编辑自定义属性…

接受并添加以下内容: idea.max.intellisense.filesize = 3000 (3000或任何大于R文件大小的值)

最后,重启你的Android Studio!

其他回答

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

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

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

在一个非基础特性的即时应用活动中,你可以调用R.id.fromFeatureOne和R.is.fromFeatureTwo。因此,来自不同资源的项目被引用为单一资源来源。

两者都将被高亮显示为可接受的,您甚至可以跳转到源代码。但是构建会导致一个错误:“不能找到符号R.id”,这是相当棘手的原因,因为什么都没有突出显示。

解决方案是调用com.example.feature.one.R.is.fromFeatureOne和com.example.feature.two.R.is.fromFeatureTwo。

在谷歌:https://issuetracker.google.com/u/0/issues/77537714也发布了一个bug

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

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

import android.R.*;