Magic behind R.java file

LambergaR picture LambergaR · Jan 12, 2010 · Viewed 47k times · Source

Recently I have been having quite some problems with R.java file. Now I have decided to do a backup and delete the file to see what happens.

Nothing happened, so I created an empty R.java file and hoped for the best. Now Eclipse seems to figure out that the file was tampered with and even issues a warning:

R.java was modified manually! Reverting to generated version!

And that's all there is. I tried building it manually but got no results.

So, I have two questions:

  1. what should I do to force Eclipse to regenerate the file
  2. what is happening here? How is the file created, where is the code that is generating the file?

I would appreciate any help. As usual the problem occurred just a few days before the deadline :)

Answer

Stan Mohler Jr. picture Stan Mohler Jr. · Aug 1, 2010

I had a problem getting my Android app to compile, with seemingly inexplicable errors about failure to generate R.java.

The problem was caused by my previously killing the Android emulator during the build. Don't do that! A clue was the appearance of several left over *.out.xml files.

The solution was to select the project, click Project->Clean, and then manually delete all the *.out.xml files. Only then could I click Run->Run and have a successful build.

One more thing: I'm using Eclipse. I had to make sure that the project was selected in Package Explorer, and not just some random source file. Easy to not notice!