“无法解析符号 R"在 Android Studio 中 [英] "cannot resolve symbol R" in Android Studio

查看:64
本文介绍了“无法解析符号 R"在 Android Studio 中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我引用 R.id.something 的所有类中的每个实例中,R 都是红色的,它表示无法解析符号 R".此外,每次有 R.layout.something 时,它都会用红色下划线表示无法解析方法 setContentView(?)".该项目始终构建良好.一直看到这个很烦人.我在这里阅读了许多其他关于类似但大多数涉及从 Eclipse 导入项目的问题.我正在使用我认为是最新版本的 Android Studio,并且该项目是使用 Android Studio 创建的,并且没有任何无法解决 R"问题.如果有人知道,我想知道是什么原因造成的.

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.

推荐答案

我使用的是 gradle 3.3.0.这是罪魁祸首.浪费了我生命中的 6.50 小时.Gradle 3.2.1 删除了错误.

I was using gradle 3.3.0. It was the main culprit. Wasted 6.50 hours from my life. Gradle 3.2.1 removed the error.

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

更改 gradle 版本后问题已解决.可以在此处找到详细历史记录.

Problem resolved after changing the gradle version. Details history can be found here.

这篇关于“无法解析符号 R"在 Android Studio 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆