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.


当前回答

//有时由于不完全同步会产生问题

//所以只要按照步骤,它会做你的工作肯定

Click on Build->Clean Project and that will perform a gradle clean

其他回答

我用的是gradle 3.3.0。它是罪魁祸首。浪费了我生命中的6.5小时。Gradle 3.2.1删除了这个错误。

classpath 'com.android.tools.build:gradle:3.2.1'

问题解决后,改变gradle版本。详情历史可以在这里找到。

在OS X和Android Studio 0.2.13上,我在com上做了“跳转到声明”。<项目>。在我的活动之一。当我回到活动文件时,所有的警告都消失了。

编辑:在此工作之前,您需要构建当前的构建变体。

我受够了

我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误

只需从根包中导入R符号

import rootpackage.R;

没有重建,同步或其他事情…

尝试确保完整的包名在第一行。假设您有一个名为LoginActivity.java的文件和一个名为com.domainname.project的包。

java的第一行应该是

package com.domainname.project;

这相当于在dot.net中指定“namespace”。还要确保该包与包含*.java文件的包匹配。