R is a class, auto-generated by the Android Asset Packaging Tool (aapt), that aims to maintain the references of all the provided resources. Through the nested classes of R, infact, is possible reach every type of resources (the complete list could be found in the official R reference).
Aapt (re) generate this class every time a build is executed on the project. If you use Eclipse as IDE, in the project menu you can set the build operation as automatic, selecting “Build Automatically”, so each time there is a change in your code the R class is updated.
The R class will not be generated when in at least one resource (layout, string, color … etc) there is at least an error. Eclipse in this case cannot compile the project, and you, cannot go ahead. Is important to know that Eclipse can only recognize XML parsing error and not all the other that we can do developing android apps, so be aware when you write some resources like strings, style, and layouts.
Many times during the developing of an application for Android we see the message “R cannot be resolved to a variable” that comes from the compiler. This means that the R class is not generated, infact you can see that there isn’t the R.java file in the folder “gen” (in the sub-folder that correspond to your package name). How to resolve this creepy situation? Here there is the list of some solutions that helped me in many cases:
If there are any suggestion to perform this guide write them to me, I will accept them with pleasures.
Leave a comment