Eclipse - Android 不会自动生成 R 类
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8812999/
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
Eclipse - Android not auto-generating R class
提问by Coyttl
have an odd one..
有一个奇怪的..
Using Eclipse Juno, and everything was working fine for the last couple months. At some point yesterday, while Eclipse was cleaning my project, something crashed - popped up the Windows error reporting. (Didn't catch the name of what crashed..)
使用 Eclipse Juno,过去几个月一切正常。昨天的某个时候,当 Eclipse 正在清理我的项目时,发生了一些崩溃 - 弹出了 Windows 错误报告。(没听出坠机的名字..)
Now, I have no R.java class in /gen, and nothing I've tried will generate it. On top of that, when doing a clean rebuild of the project, the Output window remains blank. (No errors, no status message.. nothing.)
现在,我在 /gen 中没有 R.java 类,我尝试过的任何方法都不会生成它。最重要的是,在对项目进行干净重建时,输出窗口保持空白。(没有错误,没有状态消息......什么都没有。)
Tried just about everything - including the latest which included reinstalling Eclipse and then ADT. Still hadn't helped. (I have NOT tried clearing the workspace metadata yet, will do that soon.)
尝试了几乎所有东西 - 包括最新的,包括重新安装 Eclipse 和 ADT。仍然没有帮助。(我还没有尝试清除工作区元数据,很快就会这样做。)
Any thoughts on what else to check?
还有什么要检查的吗?
--Fox.
- 狐狸。
Edit:Updating a random file - either .java or an XML layout/drawable does not have any effect, still nothing. Also, removing saved preferences from workspace .metdata data didn't have an effect either.
编辑:更新随机文件 - .java 或 XML 布局/可绘制文件没有任何影响,仍然没有。此外,从工作区 .metdata 数据中删除保存的首选项也没有效果。
Edit 2:Okay - not sure WHY it was happening, but creating a new project and the issue was corrected.
编辑 2:好的 - 不确定为什么会发生,但创建一个新项目并且问题已得到纠正。
So somehow either the project settings (.settings or project.settings) must have gotten corrupted. I have the origianl project still, and am curious to see why it happened, but creating a new project and copying sources and resources over, and no more issue.
所以不知何故,项目设置(.settings 或 project.settings)一定已经损坏了。我仍然有原始项目,很想知道它为什么会发生,但是创建一个新项目并复制源和资源,没有更多问题。
Thanks to all that offered comments - goes to show that any kind of little corruption can cause strange things to happen.
感谢所有提供评论的人 - 表明任何类型的小腐败都可能导致奇怪的事情发生。
回答by InsaurraldeAP
The reason in 99% of the cases is that you are missspelling something in some xml file. The R class file won't appear until all xml files are correct.
99% 的原因是您在某些 xml 文件中拼错了某些内容。在所有 xml 文件都正确之前,R 类文件不会出现。
I suggest look carefully into your XMLs for a very small syntax error.
我建议仔细查看您的 XML,以查找非常小的语法错误。
Or try taking off 1 by 1, until you figure it out wich one is the problematic.
或者尝试一个接一个地取消,直到你弄清楚哪一个是有问题的。
:) kind of annoying, i know.
:) 有点烦人,我知道。
回答by loonis
If you don't have any errors in your xml files, you tried to reboot your eclipse, your emulator, then open the sdk manager and apply all update. My R have finally been generated.
如果 xml 文件中没有任何错误,则尝试重新启动 eclipse、模拟器,然后打开 sdk 管理器并应用所有更新。我的R终于生成了。
回答by hairysocks
I found this happened after updating my Android SDK Manager and related eclipse plugins. I am running in Ubuntu, and it would not let me update the plugins unless I ran as the root user (using "sudo eclipse
")
我发现这是在更新我的 Android SDK 管理器和相关的 eclipse 插件后发生的。我在 Ubuntu 中运行,除非我以 root 用户身份运行(使用“ sudo eclipse
”),否则它不会让我更新插件
This left some of the Android SDK Manager items, and the eclipse plugins, owned by root. This stopped the "clean" working on the project - it must have been something that had been added as the root user, and not accessible as my normal user.
这留下了一些 Android SDK 管理器项目和 eclipse 插件,归 root 拥有。这停止了该项目的“干净”工作 - 它一定是作为 root 用户添加的,并且无法作为我的普通用户访问。
I had to "chown" my eclipse directory and my Android SDK Manager directory so it was owned again by my normal user:
我不得不“chown”我的 eclipse 目录和我的 Android SDK Manager 目录,以便它再次归我的普通用户所有:
cd /home/myacct/android-sdk/
chown -R myacct:myacct *
After this the clean option worked, and R was regenerated.
在此之后,干净的选项起作用了,并且重新生成了 R。
回答by alexismorin
This was it for me:
In your AndroidManifest.xml
file, make sure that you have the SDK installed for the version number in android:minSdkVersion="##"
.
对我来说就是这样:在您的AndroidManifest.xml
文件中,确保您已为android:minSdkVersion="##"
.
You can install SDKs from the Android SDK Manager, found under Window -> Android SDK Manager in Eclipse / ADT.
您可以从 Android SDK 管理器安装 SDK,该管理器位于 Eclipse / ADT 中的 Window -> Android SDK Manager 下。
回答by Kenneth Hippolite
For me it ended up being gen/com/(appname)/R.java missing. Not in my recycle bin, not anywhere... just took a surprise vacation and never returned.
对我来说,它最终是 gen/com/(appname)/R.java 丢失。不在我的回收站里,不在任何地方……只是度过了一个惊喜假期,再也没有回来。
I had a backup copy in a different folder. Copied it back and all's good now
我在另一个文件夹中有一个备份副本。复制回来,现在一切都很好