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.


当前回答

当我手动重命名应用程序的域文件夹时,我遇到了这个问题。为了解决这个问题,我不得不这样做

在AndroidManifest.xml中设置正确的<manifest>的包文件夹结构。 在AndroidManifest.xml中为android设置新的包位置:<activity>的名称。 清除缓存

文件菜单-> Invalidate cache / Restart…

一旦Android工作室重新启动并构建新的索引,这个问题就会消失。

其他回答

这个符号看起来很好用。

android:id="@+id/viewID"

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

同样的问题。当我在我的可绘制文件夹中添加了一些图像并试图访问它们时开始。此外,添加的图像有大写字母的扩展名。这似乎使构建崩溃,因为即使我重命名它们,消息也是一样的,R是不可访问的。我所做的是,在.iml文件中,我寻找了excludeFolder并删除了它们(如下图所示):

  <excludeFolder url="file://$MODULE_DIR$/build/apk" />
  <excludeFolder url="file://$MODULE_DIR$/build/assets" />
  <excludeFolder url="file://$MODULE_DIR$/build/bundles" />
  <excludeFolder url="file://$MODULE_DIR$/build/classes" />
  <excludeFolder url="file://$MODULE_DIR$/build/dependency-cache" />
  <excludeFolder url="file://$MODULE_DIR$/build/incremental" />
  <excludeFolder url="file://$MODULE_DIR$/build/libs" />
  <excludeFolder url="file://$MODULE_DIR$/build/manifests" />
  <excludeFolder url="file://$MODULE_DIR$/build/res" />
  <excludeFolder url="file://$MODULE_DIR$/build/symbols" />
  <excludeFolder url="file://$MODULE_DIR$/build/tmp" />

在那之后,我重建了项目,R神奇地重新出现了。

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

import android.R.*;

这是最近删除的xml造成的 在Android Studio中,从这些xml中清除你的项目,选择: Build ->清洁项目

这不是错误。 如果你有错误 关闭项目。 然后打开项目 在此之后,您可以得到一个错误

Cannot resolve symbol 'default_web_client_id'

可以通过在sting值中插入Web客户端ID来解决