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.
当前回答
对我来说,问题是我升级到一个似乎有一些bug的Gradle版本。3.4.0-alpha02是我更新到的,发现这是“无法解析符号R”错误的罪魁祸首。我恢复到3.3.0-alpha10(即类路径'com.android.tools.build:gradle:3.3.0-alpha10'),它解决了这个问题。
这显然不是一个持久的解决方案,因为我迟早需要升级,但截至2018年11月3日,3.4.0-alpha02是最新版本,它阻碍了我的开发,因为它不允许我通过单击R引用在IDE中跳跃。
其他回答
我确实做了一个项目,而且成功了 但在此之前,请尝试检查清单中的包名称,重新构建并清理项目。如果问题没有解决,那就放弃你的项目
我不得不在android studio中导入我的R包。例如:import com.example。<包名称>。R
当我导入google服务时,我就遇到了这个问题。json文件来实现分析。我已经在xml文件夹中有global_tracker.xml文件。在构建过程中,合并来自google-services的内容。Json文件,错误开始发生。
删除google -services后,该错误得到解决。json文件。
你的代码被打乱了。答案相当简单。
点击构建->清洁项目。
这样应该可以了。
检查你的Android Studio版本。
我目前使用的是Android Studio 3.0.1。
如果你在移动java文件或目录到其他位置后看到这个错误,那么你可以保证Android Studio已经混淆了。你猜怎么着?撤销这些操作并不能解决问题。
所以你试着戒毒,但没用。
重启也不行。
但是试试文件->无效缓存/重新启动…->失效并重启
Android Studio维护哪些文件依赖于哪些其他文件的信息。由于移动文件没有正确实现,因此移动文件会导致错误。这还不是全部:这些依赖项的缓存被用于加速构建。
这意味着您不仅必须重新启动,而且还需要使这些缓存失效以恢复(或者更准确地说,重新构建)正常运行。
推荐文章
- 我可以设置“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?