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 IDE(我也尝试了Intelligent IDEA,它们是在相同的情况下),R.java文件不能很好地解析,总是掉在红线中。
就像这样:
这几乎让我疯了,我不能忍受读取颜色当我编程。
最后我发现这个棘手的问题是由我的R.java的文件大小引起的。 我的项目非常庞大,它支持多种语言和多种屏幕尺寸。资源太多了,我的R.java文件大小大约是2.5M。
Android Studio中文件的最大大小默认设置为2.5M,因此大于这个限制的文件不能很好地解析。您可以在“AndroidStudio-root/bin/idea.properties”中更改默认设置。
更改这一行:
idea.max.intellisense.filesize=2500
to :
idea.max.intellisense.filesize=5000
然后重新启动Android studio,红色消失,我又可以愉快地编程了。
其他回答
“我也遇到过同样的问题,解决方法是:
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.`
首先检查是否有任何错误在任何xml布局,如果然后解决它首先。
否则,从项目中删除junit依赖项并重新构建项目。
只需进入Android Top菜单列表。点击构建菜单,在构建下点击重建项目。
我用的是gradle 3.3.0。它是罪魁祸首。浪费了我生命中的6.5小时。Gradle 3.2.1删除了这个错误。
classpath 'com.android.tools.build:gradle:3.2.1'
问题解决后,改变gradle版本。详情历史可以在这里找到。
对于这个问题,我有一个特例。
在我的项目中,一切都很顺利,它可以编译和构建成功,但在我的Android Studio IDE(我也尝试了Intelligent IDEA,它们是在相同的情况下),R.java文件不能很好地解析,总是掉在红线中。
就像这样:
这几乎让我疯了,我不能忍受读取颜色当我编程。
最后我发现这个棘手的问题是由我的R.java的文件大小引起的。 我的项目非常庞大,它支持多种语言和多种屏幕尺寸。资源太多了,我的R.java文件大小大约是2.5M。
Android Studio中文件的最大大小默认设置为2.5M,因此大于这个限制的文件不能很好地解析。您可以在“AndroidStudio-root/bin/idea.properties”中更改默认设置。
更改这一行:
idea.max.intellisense.filesize=2500
to :
idea.max.intellisense.filesize=5000
然后重新启动Android studio,红色消失,我又可以愉快地编程了。
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)