Question

I accidently deleted my R.java after cleaning the project (Project->Clean). 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.

Was it helpful?

Solution

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)
  • Did Project->clean another time (failed)
  • Deleted the gen folder and waited until adt will re-create it (failed)

The answer:

  • Created new project and copied the files that not auto generated (succeeded)

OTHER TIPS

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.

  • After you have deleted the gen directory, go to Project > Clean ...
  • You should have errors indicating that R cannot be resolved to a variable. Right click on your project from the Package Explorer and select Build Project. Be sure Build Automatically option is turned off (uncheck in Project > Build Automatically).
  • Errors regarding R should have now disappeared. Now, perform a Project Clean once again. All errors should be gone.

Let me know if this works for you.

Build the project again an do not worry, R.java is generated each time the project is built

I will automatically create by eclipse no need to create by us. just build the project i.e save the changes will automatically build it for u.

R.java file is automatically created when you build the workspace, so it should be generated again with the next cleaning of project, unless you have errors in java or xml files, so check if you have errors in your project and correct them first.

In the eclipse you have down to the clean project you have option Build Automatically try to enable it....

Just click Project > Build Project

When you build the project, you don't get R.java.
You should check external library. Just remove the external library and add external library.

Android projects get tangled easily.

Just Restart the Eclipse will solve this Issue as the workspace will be freshly 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.....

Moreover, this technique always works when the R.java file is deleted and not restored back immediately !

Evenafter the problem persists then make a new project and add copy ur xml and java files to that project , delete the previous one . . . .

I had a similar problem: building the project, the R.java file was missing. I built the project, but there were errors in the resource XML file. 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.

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.

What I did to fix was:

  • revert to older version (I used Github)
  • R.java still missing so I deleted "gen" and "bin" folders
  • R.java was generated and errors disapeared

This was done using Eclipse Luna. Good luck.

Gradle Project Tab

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. I ran anything that had to do with processing or updating or generating resources. final one I did was "processDebugResources"

missing R folder

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top