views:

2202

answers:

9

Hi!

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 hopped for the best. Now Eclipse seems to figure out that the file was tempered 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 generate 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 :)

A: 

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.

ponkin
Yes I have. There are loads of problems in my problems, hope you don't expect me to delete every single reference to R.java in all my classes...
LambergaR
2LambergaR: I mean that you should check your xml/aidl/AndroidManifest.xml first. May be there are some problems, and that`s why eclipse can`t generate R.java.
ponkin
I have checked it ... it is OK
LambergaR
+1  A: 

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.

Tomas
That's exactly what I have done - first I deleted the file, but eclipse did not even detect it being gone. Only after I created an empty R.java class it detected there was something wrong, but it doesn't recreate or in any way modify the file.
LambergaR
A: 

Option #1: I seem to recall Eclipse has some sort of force-build option you can try.

Option #2: Go into the project's main directory. Run android update project -t ... -p ., where the ... indicates whatever Android target you are targeting (e.g., android-6 for Android 2.0.1 sans Google Maps -- run android list targets for your options). This will give you the Ant build scripts. Run ant debug, which should generate your R.java file (assumes you have Apache Ant installed). At that point, you can resume your Eclipse-based building.

CommonsWare
A: 

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

zorglub76
A: 

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?

LambergaR
The error about the 9-patch should've showed up in the 'Problems' window.
Roman Nurik
It might have been present somewhere, but it crashed R.java the moment I added it to the project and everything turned red, so it was sort of hard to notice.
LambergaR
A: 

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 file?

duanemat
Creating my own (empty!) R.java file was the last thing I have done. When it completely failed on me I first tried to clean up the project, rebuild it manually, then I have deleted the file and rebuilt the project (nothing happened). So finally I have created a new class, naming it R.java - at first an empty class, then I added the basic classes (array, attr, drawable, id, layout and string), at that point the system realized the R.java was changed and tried to rebuild it - failing miserably in the process.
LambergaR
+1  A: 

Make sure there are no errors is your Manifest file. If you delete the resource string app_name in /res/values/strings.xml, it doesn't know how to generate R.java right. I found this a problem when doing the HelloSpinner tutorial.

Sven
A: 

Hi Something that can be good to know is that if an XML file contains a ?, then R.java is not regenerated and the error is not shown in the XML file (sometimes it shows up after a while) I you have a line similar to:
< string name="questionmark">?< /string>
try to change the ? to something else and see what happens to the R.java file - worked for me

Jacob
A: 

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!

Stan Mohler Jr.