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工作室修复了这个问题。

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

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.`

我也有同样的问题: 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

在我做“建立->清洁项目”和“同步项目与gradle”。它们都不是解。我从3.3.0 => 3.2.1(恢复为项目初始状态)下构建gradle版本,它解决了我的问题。

在xml文件中简单地定义一个应用程序名称空间就会导致这种情况。这是一个完全无害的行,只选择了一个符号(从许多符号中)来解析。简单地删除整行,在下面的图片中灰色,使我的代码引用未解析的符号。甚至当我添加回线,它决定没有问题。图。