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.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:id="@+id/viewID"

Android Studio的设计面板似乎不太好用。

我想我有终极解决方案了。我做了一项研究,发现Android Studio讨厌在安装路径或目录中设置“空白”。它不接受放置在包含空白的目录中的SDK。例如

C: \ Program Files \ Android \ sdk (x86)

此目录无效,因为它包含空白。在这里,我已经回答了一个问题,一个人无法在Android Studio中更改他的JDK路径,因为他的SDK目录中有一个空白。这很奇怪,但似乎Android Studio讨厌有空格的目录。所以解是-

将Android Studio和Android SDK安装在一个没有任何空白的目录或路径中。

例如-安装Android Studio

C:\AndroidStudio\

并安装Android SDK

C:\Sdk\

这两个目录都是有效的,因为没有任何空白。每个不包含空格的路径都是有效的。它还解决了其他问题,如“Failed to resolve: junit:junit:4.12”或“Gradle同步项目失败”等。

我受够了

我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误

我在清理建筑。Gradle和这个错误出现。

一大堆“清理和重建”的答案。这些对我都没用。

最后,我发现我无意中复制粘贴了build.gradle中错误的“命名空间”名称。修复了它,它运行。

确保项目中有AndroidManifest.xml。

我导入的项目还没有manifest,所以Android Studio不会将其识别为Android项目。然后我在GIT中拉了这个项目,它下载了清单,但仍然不能工作。 然后我重新启动Android Studio,它说“框架检测到Android”。

确保你的项目配置为Android项目。