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.
当前回答
注意:这可能只在您的项目非常大时才有用
TL;DR -生成的R文件超过2.56 MB, Android Studio没有索引它,你可以在这里遵循解决方案:
文件大小超过配置限制(2560000),代码洞察功能不可用
也面临着类似的问题。但这里的答案似乎都不奏效。
R文件大于2.56 MB,在打开生成的R文件时,我收到一条消息说“代码洞察可能不可用”
改变默认的想法。属性,以允许更大的文件,这是有效的。
很抱歉在移动设备上设置了格式。
其他回答
在xml文件中简单地定义一个应用程序名称空间就会导致这种情况。这是一个完全无害的行,只选择了一个符号(从许多符号中)来解析。简单地删除整行,在下面的图片中灰色,使我的代码引用未解析的符号。甚至当我添加回线,它决定没有问题。图。
The above answers are also the ways to fix the error but if does not work for anyone then i have an option...
只需要关闭项目,然后重新启动它,这样它就会加载引用… 跟着截图走。
看看Gradle控制台。在我的例子中,我包含了一个文件扩展名错误的资源。
AAPT: libpng error: Not a PNG file
:app:mergeDebugResources FAILED
FAILURE: Build failed with an exception.
在重命名文件和同步项目与Gradle文件之后,一切都很好。
我也遇到过类似的问题,我是这样做的:
清洁项目和同步项目与Gradle,
检查buildTools版本在我的sdk
从build gradle (module)中将minSdkVersion从8修改为9
defaultConfig {
applicationId "PackageName"
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
但这一切都无济于事。
最后我找到了答案(这对我来说很管用)
从build.gradle(module:app)更改
android {
compileSdkVersion 21
buildToolsVersion '21.0.1'
......
....
}
Or
选择文件|项目结构将构建工具版本更改为21.1.1
我正在做一个多模块的项目。这发生在我把所有ui代码移到一个新模块时。
下面是我解决这个问题的方法: 我发现当我创建新的ui模块时,在/res/values中,它创建了一个新的strings.xml,其中没有任何有用的东西。 我删除了strings.xml文件,重新构建项目,它工作了。
推荐文章
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器
- Android命令行工具sdkmanager总是显示:警告:无法创建设置
- 如何设置RecyclerView应用程序:layoutManager=""从XML?
- 在没有开发服务器的情况下在设备上构建和安装unsigned apk ?
- 操作栏和新引入的工具栏有什么不同?
- 调整浮动动作按钮图标大小(fab)
- Android Studio无法找到有效的Jvm(与MAC OS相关)