简体   繁体   English

清理项目后删除R.java

[英]R.java was deleted after cleaning the project

I accidently deleted my R.java after cleaning the project (Project->Clean). 清理项目(Project-> Clean)后,我不小心删除了R.java Is there any way to restore or re-create the file? 有什么办法可以还原或重新创建文件?

I tried to build the project but R.java still missing from the project. 我尝试构建该项目,但该项目中仍然缺少R.java

Here's a the things I ahve tried. 这是我尝试过的东西。

  • Rebuilding the project (failed) 重建项目(失败)
  • Manually creating R.java and wait until the adt will generate the content (failed) 手动创建R.java并等待直到adt生成内容(失败)
  • Did Project->clean another time (failed) Project->clean了一次(失败)
  • Deleted the gen folder and waited until adt will re-create it (failed) 删除了gen文件夹,并等待直到adt重新创建它(失败)

The answer: 答案:

  • Created new project and copied the files that not auto generated (succeeded) 创建新项目并复制未自动生成的文件(成功)

You have to build the project to be able to use the newly added resources. 您必须构建项目才能使用新添加的资源。

Cleaning a project removes all auto-generated files. 清理项目会删除所有自动生成的文件。 Building the project it should automatically create them. 构建项目时,它应该自动创建它们。 When you Clean a project, there's an option to start a build immediately after clean up. 当您清理项目时,可以选择在清理后立即开始构建。

Here's a few things you can try (did the same procedure after manually deleting the "gen" directory. 您可以尝试执行以下操作(手动删除“ gen”目录后,执行了相同的步骤。

  • After you have deleted the gen directory, go to Project > Clean ... 删除gen目录后,转到“项目”>“清理...”。
  • You should have errors indicating that R cannot be resolved to a variable. 您应该有表明R无法解析为变量的错误。 Right click on your project from the Package Explorer and select Build Project. 在Package Explorer中右键单击您的项目,然后选择Build Project。 Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically). 确保已关闭“自动构建”选项(在“项目”>“自动构建”中取消选中)。
  • Errors regarding R should have now disappeared. 有关R的错误现在应该已经消失了。 Now, perform a Project Clean once again. 现在,再次执行项目清理。 All errors should be gone. 所有错误都应该消失。

Let me know if this works for you. 让我知道这是否适合您。

再次构建项目,不用担心,每次构建项目时都会生成R.java

I will automatically create by eclipse no need to create by us. 我将由eclipse自动创建,而无需由我们创建。 just build the project ie save the changes will automatically build it for u. 只需构建项目,即保存更改将自动为您构建。

R.java文件是在构建工作空间时自动创建的,因此除非下次在java或xml文件中存在错误,否则应在下次清理项目时再次生成该文件。因此,请检查您的项目中是否存在错误,并首先对其进行更正。

在Eclipse中,您可以进入清理项目,然后选择“ 自动构建”选项以尝试启用它。

Just Restart the Eclipse will solve this Issue as the workspace will be freshly Build ! 只需重新启动 Eclipse就可以解决此问题,因为工作区将是Build! go to

File -> Restart 文件->重新启动

Try this method by first right click on ur project folder -> Close Unrelated Projects ! 通过首先右键单击您的项目文件夹-> 关闭不相关的项目,尝试这种方法!

Its the fastest way to avoid frustration by going it into Build,preferencen,properties,blah blah..... 通过进入Build,preferencen,properties,等等等等,它是避免沮丧的最快方法。

Moreover, this technique always works when the R.java file is deleted and not restored back immediately ! 此外,当删除R.java文件并且不立即还原时,此技术始终有效!

Evenafter the problem persists then make a new project and add copy ur xml and java files to that project , delete the previous one . 即使问题仍然存在,然后创建一个新项目并向该项目添加ur xml和java文件副本,然后删除前一个项目。 . . .

Just click Project > Build Project 只需单击项目>构建项目

When you build the project, you don't get R.java. 在生成项目时,不会得到R.java。
You should check external library. 您应该检查外部库。 Just remove the external library and add external library. 只需删除外部库并添加外部库即可。

Android projects get tangled easily. Android项目很容易纠结。

I had a similar problem: building the project, the R.java file was missing. 我有一个类似的问题:构建项目,缺少R.java文件。 I built the project, but there were errors in the resource XML file. 我构建了项目,但是资源XML文件中有错误。 Correct them, then rebuild. 纠正它们,然后重建。 When there were no errors anymore, the R.java was recreated and contained all the R.id.xxx items I had inserted in the resource. 当不再有错误时,将重新创建R.java,并包含我在资源中插入的所有R.id.xxx项目。

This recently happened to me (10 mins ago) for my Android project, and my solution was a mix of things I read in some answers here. 这是最近(10分钟前)发生在我的Android项目上的,我的解决方案是我在此处的一些答案中所读到的内容的混合体。

What I did to fix was: 我要做的修复是:

  • revert to older version (I used Github) 恢复为旧版本 (我使用Github)
  • R.java still missing so I deleted "gen" and "bin" folders R.java仍然丢失,因此我删除了 “ gen”和“ bin”文件夹
  • R.java was generated and errors disapeared R.java生成并且错误消失了

This was done using Eclipse Luna. 这是使用Eclipse Luna完成的。 Good luck. 祝好运。

Gradle Project Tab Gradle项目标签

I tried clicking all the stuff under Gradle Projects tab, and noticed a few small errors, example: I had a capital letter in the drawable folder. 我尝试单击“ Gradle项目”选项卡下的所有内容,并注意到一些小错误,例如:我在drawable文件夹中有一个大写字母。 I ran anything that had to do with processing or updating or generating resources. 我跑了所有与处理,更新或生成资源有关的东西。 final one I did was "processDebugResources" 我做的最后一个是“ processDebugResources”

missing R folder 缺少R资料夹

I had also noticed the folder circled in the above image was missing, running "processDebugResources" seemed to have regenerated the folder, although the others I clicked under the Gradle Projects tab could have also helped 我还注意到上面图像中圈出的文件夹已丢失,运行“ processDebugResources”似乎已重新生成了该文件夹,尽管我在Gradle Projects选项卡下单击的其他文件夹也可能有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM