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.
当前回答
注意:这可能只在您的项目非常大时才有用
TL;DR -生成的R文件超过2.56 MB, Android Studio没有索引它,你可以在这里遵循解决方案:
文件大小超过配置限制(2560000),代码洞察功能不可用
也面临着类似的问题。但这里的答案似乎都不奏效。
R文件大于2.56 MB,在打开生成的R文件时,我收到一条消息说“代码洞察可能不可用”
改变默认的想法。属性,以允许更大的文件,这是有效的。
很抱歉在移动设备上设置了格式。
其他回答
我正在做一个多模块的项目。这发生在我把所有ui代码移到一个新模块时。
下面是我解决这个问题的方法: 我发现当我创建新的ui模块时,在/res/values中,它创建了一个新的strings.xml,其中没有任何有用的东西。 我删除了strings.xml文件,重新构建项目,它工作了。
我今天升级了gradle版本和gradle插件版本的最新版本,它为我工作。
之后,同步项目与gradle文件。
我也有同样的问题: 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
第一个解决方案
Rebuild your gradle or invalidate/restart your system.
第二个解决方案
delete .gradle and .idea folder from your android project. So you can solve "R" problem
并且还消除了红线错误发生的任何原因你得到。
在我的例子中,当我试图从另一个包调用R时,出现了这个错误。导入R包解决了我的问题。
import com.mtdaps.yourapp.R;
推荐文章
- 我可以设置“android:layout_below”在运行时编程?
- Android Studio谷歌JAR文件导致GC开销限制超过错误
- 为什么每当我创建一个新项目时,Eclipse都会自动添加appcompat v7库支持?
- 如何同步项目到GitHub与Android工作室?
- Keytool错误:java.io。IoException:错误的AVA格式
- GCM与PHP(谷歌云消息传递)
- 自定义圆圈按钮
- 我如何使用一个复合绘图而不是一个线性布局,包含一个ImageView和一个TextView
- 如何绘制一个线性布局的边界
- 如何动画添加或删除Android列表视图行
- 如何解决“丢失的PendingIntent可变性标志”在android api 30+ lint警告?
- 我怎么能修复“意外元素<查询>发现<manifest>”错误?
- Android房间-自动生成新插入行的id
- Android Studio在哪里保存ProGuard映射文件?
- 我如何从资产文件夹解析一个本地JSON文件到一个ListView?