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 Studio 3.2 该项目编译和运行良好,但我在屏幕上得到“无法解析符号“R”的警告

没有帮助:

构建——>清洁项目 构建- >重建项目 文件- >缓存失效/重新启动

帮助:

要么

在build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
...
}

替换为

   dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'
    ...
    }

or

更新Android Studio到3.3

其他回答

//有时由于不完全同步会产生问题

//所以只要按照步骤,它会做你的工作肯定

Click on Build->Clean Project and that will perform a gradle clean

首先检查是否有任何错误在任何xml布局,如果然后解决它首先。

否则,从项目中删除junit依赖项并重新构建项目。

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

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

“我也遇到过同样的问题,解决方法是:

1) Sync Project with gradle files
2) Build -> Clean Project
3) Build -> Rebuild Project
4) File -> Invalidate caches

//imp step
5) Check your xml files properly.`

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

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

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

最后,重启你的Android Studio!