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.
当前回答
最近,当我更新一个项目的很多库时,我就遇到了这种情况。没有找到R,但是我可以很好地构建和运行项目。它没有崩溃。IDE只是在所有地方显示红色。
我试过
Check for damaged/improper XMLs and images, none found Check for invalid resource file names (e.g. capitalized), none found Downgrade some libraries because maybe it was a resource conflict, not resolved Lowered compileSdkVersion and targetSdkVersion because, in the past, I encountered resource issues due to this. In this project however, that was not the case. Clean, didn't help Rebuild project, didn't help Invalidate caches/Restart multiple times, didn't help Adjusted idea.max.intellisense.filesize to a very high value, didn't help Did a Lint run, no errors found
最后,我发现降级我的Gradle构建工具(从3.3.1到3.2.1)解决了这个问题。这是我唯一要做的改变。其余内容已更新。现在,我所有的库都更新了,没有问题。
buildscript {
repositories {
google()
jcenter()
}
dependencies {
//classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
其他回答
这些在Ubuntu 12.04上都不适用。我必须做到以下几点:
sudo apt-get install lib32stdc++6
sudo apt-get install lib32z1
在那之后,我遵循了这个线程中的其他一些建议,做了Build ->清洁项目,一切都很好。
我也遇到过类似的问题,我是这样做的:
清洁项目和同步项目与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
在OS X和Android Studio 0.2.13上,我在com上做了“跳转到声明”。<项目>。在我的活动之一。当我回到活动文件时,所有的警告都消失了。
编辑:在此工作之前,您需要构建当前的构建变体。
我受够了
我可绘制资源中的一个大写字母。 导入安卓。R由Android Studio(或Eclipse)添加 xml文件错误
上面的答案对我没有帮助。我最终意识到问题在于Android Studio中缺少“build”文件夹。我在项目“iml”文件中发现了一些行,不包括“build/*”。删除这些错误后,生成文件就出现了,错误就消失了。
推荐文章
- BottomSheetDialogFragment的圆角
- 在应用程序启动时出现“无法获得BatchedBridge,请确保您的bundle被正确打包”的错误
- 我如何改变默认对话框按钮的文本颜色在安卓5
- 更改单选按钮的圆圈颜色
- 如何在android中复制一个文件?
- adb找不到我的设备/手机(MacOS X)
- Android Studio中的。iml文件是什么?
- 如何在新的材质主题中改变背面箭头的颜色?
- androidviewpager与底部点
- 相同的导航抽屉在不同的活动
- 如何从视图中获得托管活动?
- 单一的TextView与多种颜色的文本
- 如何在非活动类(LocationManager)中使用getSystemService ?
- 在清单中注册应用程序类?
- Android:从数组中编程创建旋转器