When Eclipse won’t generate/locate R.java (Updated link)
I just recently ran in to an issue where my R.java file disappeared. R.java stopped updating and I thought that going to Project->Clean would resolve the problem, or at least give me a hint about what the problem was. Instead, it left me R-less.
I found the link above, which is helpful in that it gave me a hint that one or more of my XML files has an error, which makes some sense because I was working on one of the layout files at the time. Additionally, that may explain why R.java was not updating automatically.
However, all of the layout files were syntactically correct and removing the layout file I was working on was not sufficient to trigger the regeneration of R.java file. I tried exiting Eclipse to manually create a R.java file. This got me close; upon reopening Eclipse I got the error: “R.java was modified manually! Reverting to generated version!”. Unfortunately, Eclipse just left the new empty R.java in place. A similar result when I removed R.java while in Eclipse.
Finally, after a bunch of searching, I found out how to manually run aapt in order to generate the R.java file
cd $eclipse_workspace/project; aapt package -m -J src -M AndroidManifest.xml -S res -I $path_to_android.jar
and the result was an error displayed to stdout:
AndroidManifest.xml:22: error: Error: No resource found that matches the given name (at 'label' with value '@string/highscore_label').
I couldn’t guess why Eclipse did not put that error in the Error Log or its Console. Finally, the actual problem: I had removed a string that was being used by the AndroidManifest as a label for one of my activities. A pretty simple, stupid error, that Eclipse is apparently incapable of reporting. Well, I hope someone else benefits from this. Check your AndroidManifest.xml strings carefully, by hand.