在 Eclipse 中为 Android 开发:R.java 不重新生成 [英] Developing for Android in Eclipse: R.java not regenerating

查看:28
本文介绍了在 Eclipse 中为 Android 开发:R.java 不重新生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现我的 R.java 从来没有更新过,所以它不包含关于我的新资源的信息,所以我决定删除它,并认为 Eclipse 会生成一个新资源.但这并没有发生,我现在没有 R.java.我怎样才能再生一个?

I've found out that my R.java is never updated, so it doesn't contain information about my new resources, so I decided to delete it and thought that Eclipse would generate a new one. But that didn't happen, and I don't have R.java now. How can I regenerate one?

我使用的是 Windows 7.

I'm using Windows 7.

来自其中一条评论:Doing Project -> Clean 是我遇到问题的原因.清理会删除 R.java ......无论出于何种原因插件没有重新生成文件."

From one of the comments: "Doing Project -> Clean is what caused the problem for me. Cleaning deletes R.java...and for whatever reason the plugin is not regenerating the file."

推荐答案

我发现这种情况发生在我身上,布局损坏,一切都崩溃了.放轻松,这就像你第一次学习 C 语言时的那个老错误,你忘记了一个分号,它会产生一百个错误.许多人恐慌,按下所有按钮,让事情变得更糟.

I found this happening to me with a broken layout and everything blows up. Relax, it's like that old mistake when you first learned programming C where you forget one semicolon and it generates a hundred errors. Many panic, press all the buttons, and makes things worse.

  • 确保 R. 链接到的任何内容都没有损坏.修复 XML 文件中的所有错误.如果 ADK 中的任何内容损坏,R 将不会重新生成.
  • 如果您以某种方式击中了某些东西并在您的 Activity 中创建了 import android.R,请将其删除.
  • 运行项目 -> 清理.这将删除并重新生成 R 和 BuildConfig.
  • 确保项目 -> 自动构建被勾选.如果没有,请通过 Menu -> 手动构建它项目 ->构建项目 .
  • 等待几秒钟,让错误消失.
  • 如果它不起作用,请删除/gen/文件夹中的所有内容
  • 如果仍然无效,请尝试右键单击您的项目 -> Android 工具 -> 修复项目属性.
  • 检查您的 *.properties 文件(在您的应用文件夹的根文件夹中)并确保其中的链接没有损坏.
  • 右键点击您的项目 > 属性 > Android.查看页面右侧的 Project Build Target 和 Library 部分.您的构建目标应与 AndroidManifest.xml 中的目标相匹配.因此,如果在 AndroidManifest 中将其设置为目标 17,请确保目标名称为 Android 4.2.如果您的图书馆在参考下有 X,请删除并重新添加图书馆,直到出现绿色勾号.如果您移动了一些文件和文件夹,则可能会发生这种情况.
  • Make sure that anything the R. links to is not broken. Fix all errors in your XML files. If anything in the ADKs are broken, R will not regenerate.
  • If you somehow hit something and created import android.R in your activity, remove it.
  • Run Project -> Clean. This will delete and regenerate R and BuildConfig.
  • Make sure Project -> Build Automatically is ticked. If not, build it manually via Menu -> Project -> Build Project .
  • Wait a few seconds for the errors to disappear.
  • If it doesn't work, delete everything inside the /gen/ folder
  • If it still doesn't work, try right-clicking your project -> Android Tools -> Fix Project Properties.
  • Check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.
  • Right-click your project > properties > Android. Look at the Project Build Target and Library sections on the right side of the page. Your Build Target should match the target in your AndroidManifest.xml. So if it's set to target 17 in AndroidManifest, make sure that the Target Name is Android 4.2. If your Library has an X under the reference, remove and re-add the library until there's a green tick. This might happen if you've moved a few files and folders around.

这通常发生在您的 XML 文件损坏时.

This usually happens when you have a broken XML file.

  • 检查 XML 文件中的错误,主要位于 /res/ 文件夹中
  • 常见的地方是 /layout//values/,尤其是如果您最近更改了其中之一
  • 检查AndroidManifest.xml.我发现我经常更改字符串而忘记从 AndroidManifest.xml 更改字符串名称.
  • 检查 Android SDK Build-tools 是否已安装.窗口 -> Android SDK 管理器 -> 工具 -> Android SDK 构建工具
  • 确保在更新 Android SDK 工具 时,同时更新 Android SDK Platform-toolsAndroid ADK Build-tools.如果它们不匹配,构建会以静默方式失败.
  • 如果找不到问题,右键单击/gen/-> 从本地历史记录中恢复... -> 勾选 R.java -> 单击恢复.即使没有解决问题,它也会清除多余的错误,使问题更容易找到.
  • Check errors inside your XML files, mainly within the /res/ folder
  • Common places are /layout/ and /values/, especially if you've changed one of them recently
  • Check AndroidManifest.xml. I find that often I change a string and forget to change the string name from AndroidManifest.xml.
  • Check that Android SDK Build-tools is installed. Window -> Android SDK Manager -> Tools -> Android SDK Build-tools
  • Make sure when you update the Android SDK Tools, you also update the Android SDK Platform-tools and Android ADK Build-tools. Build fails silently if they don't match.
  • If you can't find the issue, right click /gen/ -> Restore from local history... -> tick R.java -> click Restore. Even if it doesn't solve the problem, it will clear out the extra errors to make the problem easier to find.

这篇关于在 Eclipse 中为 Android 开发:R.java 不重新生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆