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和这个错误出现。
一大堆“清理和重建”的答案。这些对我都没用。
最后,我发现我无意中复制粘贴了build.gradle中错误的“命名空间”名称。修复了它,它运行。
其他回答
我也有这个问题。简单的“gradlew clean”和“gradlew build”就成功了。
点击Build->Clean Project,将执行gradle Clean
“我也遇到过同样的问题,解决方法是:
1) Sync Project with gradle files
2) Build -> Clean Project
3) Build -> Rebuild Project
4) File -> Invalidate caches
//imp step
5) Check your xml files properly.`
还有一件事要尝试……
删除Build文件夹 通过同步gradle重新构建项目
我已经试过很多其他的建议了,比如
清洁项目, 重新启动Android Studio, 修复错误在我的xml, 同步项目与Gradle文件,以及 更新构建工具版本,
但这些都不起作用。
我最终手动删除了整个构建文件夹(在备份我的项目后),然后重新启动Android Studio。之后,我在我的应用程序构建中做了一个小编辑(添加和删除一个空格)。Gradle文件,然后点击同步。(我可能只需要从菜单中使用Gradle文件完成Tools > Android > Sync Project。)从那以后,它起作用了。在构建文件夹中已经损坏了一些东西,并开始与一个新的构建修复它。
我不知道有没有人读到这么远的答案,但我还是要加上这个答案。
上面的答案对我没有帮助。我最终意识到问题在于Android Studio中缺少“build”文件夹。我在项目“iml”文件中发现了一些行,不包括“build/*”。删除这些错误后,生成文件就出现了,错误就消失了。
在新的android studio 2.2中。如果你的TargetSDK =< 15,那么你也可能会发现这个问题。在gradle中改变这个。构建,然后按照前面的答案执行步骤。同步gradle文件并重建。您还可以使缓存无效并重新启动工作室,这有时也有帮助。
推荐文章
- 在应用程序本身中更改Locale
- apk (.apk)和应用程序包(.aab)的区别
- 如何设置超时在改造库?
- Android - SPAN_EXCLUSIVE_EXCLUSIVE跨度不能为零长度
- TextView的字体大小在Android应用程序改变字体大小从本机设置
- 如何模拟Android杀死我的进程
- 禁用EditText闪烁光标
- Android Eclipse -无法找到*.apk
- 设置TextView文本从html格式的字符串资源在XML
- 如何允许所有网络连接类型HTTP和HTTPS在Android(9)馅饼?
- Android加载JS包失败
- Android Studio, logcat在应用程序关闭后清理
- 在android中从上下文获取活动
- 无法解析主机"<URL here>"没有与主机名关联的地址
- getActivity()在Fragment函数中返回null