Annoying Eclipse Android R.java problem

September 29, 2014

Hmm, before committing my project to Mercurial source control I like to run a clean so that nothing that’s part of a build shows up as a change that I don’t want to commit (although I’ve added lines to .hgignore to ignore any generated class files and the gen directory where the ADT auto generates some files  so this probably wasn’t even necessary).

When I came back to my project at a later date there were errors in all of my activity classes, turns out that the auto generated R.java file had been deleted and was stubbornly refusing to be re-generated and so anything that depended on this (lots of stuff!) had errors, really f**king annoying.

I never found a satisfactory solution to this problem and eventually restarted the project from scratch as I’d only really just started it anyway, Google gave me few suggestions from other people but none of them worked, it seems a lot of people have had this issue. Here are some of the popular suggestions that have worked for other people.

  • Clean/rebuild – These options are under the ‘project’ menu in the main Eclipse menu, usually the project is set to build automatically whenever changes are saved so after a clean a build is usually performed, if it’s not the clean dialogue gives you the option to build immediately after a clean.
  • Deleting gen – This should cause gen and everything under it to be re-generated, the directory itself and BuildConfig.java were re-generated for me but not R.java.
  • Setting derived to false on gen – You can check this by right clicking on the file in Eclipse and selecting properties, apparently if you put gen under source control when it’s pulled out it can have the derived property set, as I didn’t have gen under source control this was never the case for me.
  • Restart Eclipse.

So far everything has been fine since, perhaps I’d missed out a file that should have been under source control which then got deleted on a Mercurial ‘update’ command? I guess the takeaway lesson for me is to be extremely careful to make sure any changes that should be committed are before updating or pulling code.

Came across this again today and found a fairly comprehensive list of things to try on Stack Overflow here http://stackoverflow.com/questions/2757107/developing-for-android-in-eclipse-r-java-not-generating.

Second answer is most useful I think.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: