eclipse Android R 文件未生成
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16726544/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Android R file not generating
提问by Ryan Sayles
I know there are a lot of threads about this but I couldn't find one that solved my problem or is a duplicate.
我知道有很多关于此的主题,但我找不到解决我的问题或重复的主题。
So I was working on an app, accidently made the mistake of cleaning my project. This caused my R.java
file to disappear. I tried cleaning my project again, building it again, closing eclipse, deleting the gen
folder, checking all of my xml files for errors, all of that.
所以我正在开发一个应用程序,不小心犯了清理我的项目的错误。这导致我的R.java
文件消失。我尝试再次清理我的项目,再次构建它,关闭 eclipse,删除gen
文件夹,检查我所有的 xml 文件是否有错误,所有这些。
Problem now is whenever I create a new completely blank application project that doesn't even generate an R
file automatically. I'm hoping there is still a way to restore it for my original project but as I stated nothing seems to work.
现在的问题是每当我创建一个新的完全空白的应用程序项目时,它甚至不会R
自动生成文件。我希望仍有办法为我的原始项目恢复它,但正如我所说,似乎没有任何效果。
回答by Andrey
It could be if you have deleted
可能是如果您已删除
<string name="action_settings">Settings</string>
in the strings.xml, but not deleted main.xml file in the menu folder.
在strings.xml中,但没有删除menu文件夹中的main.xml文件。
回答by Giant
have you tried checking for the target API maybe the api is low try doing right click your project >> properties >> andriod >> check the correct API or check if there are any error and fix them first these steps made my r file generate hope it makes yours
您是否尝试过检查目标 API 可能 api 较低 尝试右键单击您的项目 >> 属性 >> andriod >> 检查正确的 API 或检查是否有任何错误并首先修复它们这些步骤使我的 r 文件产生希望它使你的
回答by Maksim Dmitriev
I have just had this experience. In my AndroidManifest.xml
there was a reference to a theme which didn't exist.
我刚刚有过这样的经历。在我的AndroidManifest.xml
有一个不存在的主题的参考。
For instance.
例如。
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme_Lorem" >
There wasn't AppTheme_Lorem
among the application's themes
有没有AppTheme_Lorem
应用程序的主题中
回答by Nizam
If newly created projects doesn't generate R.java file, most probably the adbis not running.
如果新创建的项目没有生成 R.java 文件,很可能adb没有运行。
Solution:
解决方案:
- Make sure, there is an executable file named adbat /SDK folder/platform-tools/adb
- If you are on Linux platform, make sure it is not locked and is executable.
Right click on adb -> permissions -> Tick on the check box "Execute/Run as a program".
- 确保/SDK 文件夹/platform-tools/adb 中有一个名为adb的可执行文件
- 如果您使用的是 Linux 平台,请确保它没有被锁定并且是可执行的。
右键单击 adb -> 权限 -> 勾选“作为程序执行/运行”复选框。
回答by Bebin T.N
If any resource file name contains Caps Letter means doesn't generate R.java file. Otherwise you can modify some changes or put space in Android Manifest file and save the project. If it is not generated means you can use project clean or close the editor and reopen it. It will work.
如果任何资源文件名包含大写字母,则表示不会生成 R.java 文件。否则,您可以修改一些更改或在 Android Manifest 文件中放置空间并保存项目。如果未生成,则表示您可以使用项目清理或关闭编辑器并重新打开它。它会起作用。
回答by Gopalkrishna Mudaliar
I had the same issue. In my drawable folder I added a file video_Icon.jpg
after that eclipse was not able to generating R file.
我遇到过同样的问题。在我的 drawable 文件夹中,我video_Icon.jpg
在 eclipse 无法生成 R 文件之后添加了一个文件。
To fix the issue I changed the file name to video_icon.jpg
and it worked.
为了解决这个问题,我将文件名更改为video_icon.jpg
并且它起作用了。
回答by vzR
If none of the solutions above works, you could right click on your project, go to Android Toolsand select Run Lint: check for common Errors. Generally it's something in your xml files that stops the R file from being regenerated and the worst part is that there are some errors that are not signaled as being "errors". In my case there was a problem with naming the images in the drawable folder...as a piece of advice for beginners, don't use camel case for xml variables (image names buttons etc)
如果上述解决方案均无效,您可以右键单击您的项目,转到Android Tools并选择Run Lint: check for common Errors。通常,您的 xml 文件中的某些内容会阻止重新生成 R 文件,最糟糕的部分是有些错误没有被标记为“错误”。在我的情况下,在 drawable 文件夹中命名图像存在问题......作为对初学者的建议,不要对 xml 变量(图像名称按钮等)使用驼峰式大小写
回答by user4881223
Check the path of the files under /your project/res/
folder for images or any other resource in this folder and correct them.
检查文件/your project/res/
夹下文件的路径以获取图像或此文件夹中的任何其他资源并更正它们。
回答by MSIslam
Check if there is import android.R;
检查是否有import android.R;
Don't use android.R here, use a fully qualified name for each usage instead
不要在此处使用 android.R,而是为每个用法使用完全限定名称
回答by Ushal Naidoo
Sorry for the late reply but I thought this could give insight to anyone that has this problem.
很抱歉回复晚了,但我认为这可以让任何有此问题的人深入了解。
When the R file isn't generated it generally means that there is a problem with one of the layouts. It could refer to the manifest file having syntax errors or one of the layout files itself.
当未生成 R 文件时,通常意味着其中一种布局存在问题。它可以指具有语法错误的清单文件或布局文件本身之一。
Another reason could be that an image file contains upper case letters. Change it all to lower case, and use an underscore instead of a space in the file name of images.
另一个原因可能是图像文件包含大写字母。将其全部更改为小写,并在图像文件名中使用下划线而不是空格。