I've just spent half an hour trying to fathom how to get back my auto-generated R.java that magically disappeared at some point.
The usual ways of resolving issues such as clean build, restarting IDE, and wiping the screen clean with a damp cloth didn't work.
Googling around did reveal a lot of similar complaints and revived a stark deja vu feeling. The hilarious thing is that once the R guy is gone, a good chunk of your code goes red thus adding to the insult.
Rather than continuing the discovery of all the conceivable strains of the issue found in the wild, I decided to leverage the tried-and-true approach of staring at the code. Having done so for a while I spotted a few red guys under res folder. They were a leftover of my current redesign work that I was about to delete before things went awry. Sure enough, as soon as I hit Del on them the darn R thing automagically reappeared.
The moral of the story is there's just so much magic Google can do for us. Bad resources (e.g. layouts with errors) are not treated gracefully by Google Android Eclipse plugin and can deceive it into deleting R.java with no sound reason.
21 comments:
Thanks for sharing, just saved me a few hours of frustration! I was trying to rename my package and R disappeared. Reappeared after correcting references to the old package name in the XML layouts.
I can't believe I'm commenting on my own post to thank myself for sharing.
A few months in, and I totally forgot how to rectify the darn issue.
Now you can imagine how satisfying it can be to find your own post that hits the nail squarely!
This time it was an error in AndroidManifest.xml.
Live and learn...
Thanks for the hot tip. I'm an android newbie and I didn't have a clue what was going on until I found the telltale red glimmer next to a resource.
Thanks! Was scratching my head over this one as well!
Yes, thank you very much :D
THANK YOU THANK YOU!! Tried evening else..deleting a bad res file (XML) worked.
Thanks! I had an error in one of my xml files and that's why my R.java disappeared. Now everything is fine!
Cheers!
You are my sunshine, my only sunshine ... :)
Add one more caught with the same error.
Eclipse level errors were not very useful...
I had the same issue, however I discovered that there was a "untitled folder" inside my res/ folder, probably added it there by mistake, once removed, it was able to recreate R.java
Thanks. You're a lifesaver!
You just saved my life! I had entered an empty string in string.xml which caused the R file to stop updating... I did a clean to try and rectify the issue and it deleted R.java! Thanks!
Thank you! This is very helpful!!
I did have a bad XML file, and R.java disappeared. I have now got rid of the offending item, it still won't regenerate. Any ideas?
Problem solved. It was all about multiple substitutions in string resources. Frustrating, and a little scary.
Thx for pointing me to AndroidManifest.xml :) Problem solved!
thanks mate! :D
So, what if you checked
1) the res/ dir
2) android manifest.xml
and you find nothing wrong?
Does anybody know of a list of possible error places that the ADT won't report nicely?
I have 462 "problems" reported. All are "R cannot be resolved..."
:(
llappall said...
So, what if you checked
1) the res/ dir
2) android manifest.xml
and you find nothing wrong?
Does anybody know of a list of possible error places that the ADT won't report nicely?
I have 462 "problems" reported. All are "R cannot be resolved..."
:(
January 2, 2012 3:13 PM
yeah check out your import as it some times with cleaning the projeckt etc.
it will add an import android.R; remove it... and you will again use the res/xml files :)
Thanks! In my case until the warnings found in the resources were preventing the generation of automatic R.java. To fix it i setup Android Lint (Window -> Preferences -> Android -> Error Checking Lint) to mark the problems less relevant as Information instead of Warning, the damn R was created at the time!
Thank you very much for taking the time to write this. It helped me out quite a bit. I clicked an add on the side to help yo out;)
Post a Comment