Monday, March 19, 2012

Regenerating R.java

In Eclipse, under the Project menu, is an option build automatically. That would help you build the R.java file everytime modifications are made. The Clean... option is also there under Project.




http://blog.burnayev.com/2009/11/android-developer-tip-regenerating.html

 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.

No comments:

Post a Comment