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在一开始就会给学习带来麻烦,但就像这里有解决方案清洁项目可以解决这个问题,总是检查包装的名称,不要试图混乱的逻辑,我喜欢软件,但有时我试着思考如果方式是正确的或不正确,我也喜欢Linux,但对我来说,Android Studio重写所有软件也许这不会发生。总之,祝你好运!!!!

其他回答

我今天升级了gradle版本和gradle插件版本的最新版本,它为我工作。

之后,同步项目与gradle文件。

我也有这个问题。简单的“gradlew clean”和“gradlew build”就成功了。


点击Build->Clean Project,将执行gradle Clean

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

你的代码被打乱了。答案相当简单。

点击构建->清洁项目。

这样应该可以了。

检查你的Android Studio版本。

我目前使用的是Android Studio 3.0.1。

看看Gradle控制台。在我的例子中,我包含了一个文件扩展名错误的资源。

AAPT: libpng error: Not a PNG file
:app:mergeDebugResources FAILED

FAILURE: Build failed with an exception.

在重命名文件和同步项目与Gradle文件之后,一切都很好。