Magic behind R.java file

Viewed 47007

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 :)

19 Answers

R.java is autogenerated on build. It's content is based on the resource files (including layouts and preferences).

When you deleted it, it was recreated, but if you create your own, you will get into trouble as the build system will not replace it.

You can simply delete it again (manually or by choosing Project->Clean) and rebuild your program.

I found the problem - I have created a 9patch image with the patch area defined only on the Y axis (I was trying to prevent resizing on the other one).

The question remains: Why isn't there a warning about the error? Or if there is - where is it buried?

Sorry, but try to check the output in Eclipse. May be you have some errors that prevents Eclipse to finish build proccess(check your AndroidManifest.xml, is it correct?).I mean, that you should check all your resource files(string.xml, layouts, ...) and interfaces(*.aidl), may be there are some problems(inconsistent syntax, or something....) that prevent eclipse to generate R.java.

As ponkin stated - you probably have one single problem that causes R not to re-generate itself, because of which you now have one million and one problem.

Do not try to create R class yourself. Try to think of the last XML you've been messing with, and check it for errors

I've had the same problem here

As others stated, stay away from creating your own R.java file. I ran into the same problem when I first started with Android, and it took some time to figure out what caused by compilation errors.

What were you trying to do with the R.java file?

I read this on another site and it helped me:

"If that doesn't fix your problem, try modifying your AndroidManifest.xml (just add a space and save). I've heard that will force the R.java to rebuild. "

So just add a space in the manifest file and then rebuild!

Related