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
其他回答
在我做“建立->清洁项目”和“同步项目与gradle”。它们都不是解。我从3.3.0 => 3.2.1(恢复为项目初始状态)下构建gradle版本,它解决了我的问题。
我知道这个问题可能会导致很多事情。在我的例子中,我在其中一个活动*.xml文件中有一些textView。我在编辑器中放入文本(稍后通过代码更改):“NAME: <这里将是名称>”。显然,“<”和“>”字符破坏了在我的项目中从每个地方导入R。我把它换了,它开始工作了。我只是忘记了不能在*.xml文件中使用这些字符,因为它们构建了它的结构。记住这一点是值得的。
只需从根包中导入R符号
import rootpackage.R;
没有重建,同步或其他事情…
我发现在大型项目中,自动生成的R.java大于2.55MB (Intellij的默认限制),这导致文件生成但无法解析。要解决这个问题,只需提高极限:
在Android Studio帮助->编辑自定义属性…
接受并添加以下内容: idea.max.intellisense.filesize = 3000 (3000或任何大于R文件大小的值)
最后,重启你的Android Studio!
如果你在.xml文件上有任何错误,无论你做什么,你都无法修复这个问题。我建议
-首先,检查XML文件以查找任何错误和
-秒查找事件日志什么Android工作室捕捉到的错误,它会告诉你哪个文件和错误在哪里。
这就是我解决R问题的方法
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)