I would like to fix this error
R cannot be resolved to a variable
I looked up many answers, but I could not get the right one;
Tip: update SDK and all utilities else one time. It helped to me.
I had the same issue and main reason why R.java was not re-generated is errors in any of the files in the project. Once we fix those the R.java should get generated.
Just look in to your header files there will be:
import somefile.R;
Just remove that line and that's it.
I had the same problem. I didn't have any lines stating "import something.R". Cleaning and rebuilding also didn't solve the issue.
It turned out to be because of the name of a layout xml file. Those files can only contain lowercase letters, or numbers, or underscores. When I changed the filename (and everything that refers to it) from myLayout.xml to my_layout.xml, everything worked.
Nothing mentioned above worked for me. However, I fixed it myself.
If you've any other files except activity_main.xml
/ main.xml
inside app_name/res/layout
remove it and try clean and build.
The unwanted files or (rather used later) files inside app_name/res/layout
would be *.out.xml
. Remove the same.
what did it for me...
when i checked my project properties file (/project_root/project.properties
), it had a reference to an old android version target which i no longer had installed
# Project target.
target=android-15
as soon as I changed this to say 17, it worked perfectly, soon as the file was saved my gen folders were built and inflated.
# Project target.
target=android-17