This question already has an answer here:
In Eclipse, I've created a project from a source and now it shows errors - "R cannot be resolved to a variable". From what I found here, I had cleared and rebuilt the project, but still the R file doesn't appear in the /gen folder.
Any ideas?
My setup was broken after a recent update where the SDK build tools need to be installed separately after the SDK installation. So build tools update + Eclipse restart fixed this for me.
Credit goes to the Android reply here
When other solutions fail, select your project and delete it. MAKE SURE YOU DO NOT REMOVE FILES FROM DISK.
Then use file>import>existing android code into workspace, and select the location of your project.
I know this is an old question but I just solved my own version of it and perhaps this might help someone.
After two days of tearing my hair out with this, I finally got around it by deleting the
raw
folder, then recreating it and dropping the file(s) back in.After that, another
Project > Clean
and it at last compiled.My problem was strange and took some time to find. Somehow the package of the src file changed so that the last entry in the package was deleted. So for example initially my class MyActivity.java was in package com.abc.client.test.app but after I added a user permission, the app got removed and the package was renamed to com.abc.client.test. I don't know how it happened. Renaming the package and putting the java file in the correct place fixed the problem.
Project > Clean...
usually regenerates R.java file located in gen/com.mypackage
I got this error when I added a js file to the res folder.
An error indicator was set on the res folder icon. In all the classes where I used R I got this error.
I moved the js file to the assets folder and everything worked.