Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R.java disappears after project clean

Try Project->Clean in Eclipse. In my limited experience if R.java is not being automatically created then there is an error somewhere in your xml. Triple check everything.


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.


Here is what the problem was. I added those new png images to the project and android has rules as to what characters are allowed in the names of these images. Once I changed the uppercase letters in the image name, it was back on track again and Build Automatically generated the R.java file and all errors were gone. Eclipse console is the place where I found all the errors related to my resources.

Thanks Guys....I tried your solutions but my error was something specific which was due to my image naming convention so this is the way I fixed it.


I would agree this is usually a XML problem but moreover that it is something within your res folder that is the problem and may be highlighted with a red cross after the clean attempt.

I have just had this problem and it was because I had created my own folder called 'data' within res folder. After the clean it had a little red cross against it. I removed this folder and R built again.

Regards, Mark


Several things you should check in your project:

  • Check the Problems tab in your Eclipse IDE. Are you sure that you did not introduced building problems while making changes with drawables? To check that you need to check xml source of affected layout and see if something is marked red.

  • In File explorer go to the directory where your Android project is. Check that you have file default.properties (.classpath, .project and AndroidManifest.xml should be there). If default.properties is missing it may be easily replaced by correct version.

  • Which is the Android version you are working with? If that is 1.5 or lower be sure that in the res directory you have directory named drawable, not drawable-hdpi, drawable-mdpi and drawable-ldpi. Last three are valid for version 1.6 and higher.

  • Right click on your project in Package explorer in Eclipse. You will get a number of options. Go to Android Tools-> Fix Project Properties so see if that helps.


I had an invalid jpg in my res/drawable folder. I removed the jpg and it worked.


I had this problem on my Mac too and I think it could be good to know for all Mac users how I managed to solve this error.

I had a .DSStore file automatically imported to my project inside the res directory and when I removed it and rebuilt the project all went well.