Eclipse: R error cannot be resolved by variable

I get this classic error in the Eclipse IDE. I'm bored with Eclipse errors. They drive me crazy.

I almost tried everything that was suggested as a solution (Googling). None of them worked.

My project worked fine, but did not change the code.

I see that my code changes do not affect my application (on AVD), after which I cleaned up my project (under Project > Clean... ). R.java file was gone and the res folder was empty.

Now I get this error: R cannot be resolved to a variable.

What should I do?

And also I tried to delete the project and create again using the Android Project from Existing Code , which I made a backup earlier. It already gives the same error after cleaning.

Any ideas would be appreciated.

+53
android eclipse
May 20 '13 at 4:26
source share
6 answers

I assume that you have updated ADT with version 22, and the R.java file is not generated.

If so, then here is the solution:

Hope Android studio has a gradle build tool. Same as in eclipse, they provided a new component in the Tools folder called Android SDK Build-tools, which must be installed. Open the Android SDK Manager, select the new build tools, install it, restart the SDK manager after the update.

enter image description here

+122
May 20 '13 at 5:21
source share

I do not send this as an answer, but a confirmation of Paresh's accepted answer. I recently updated the SDK tools to version 22, and I noticed that my changes in the code do not affect the device that I am testing at all. For example, the URL that I used, I was getting errors for the connection time regarding the URL that I used earlier. So I cleaned up the project and built it again to find out that the auto-generated R.java file is missing.

After reading Paresh's answer and checking what is happening with my sdk manager, this is what I saw: enter image description here

Build-tools SDK 17 was not installed, and there was already a new update for SDK tools, although it does not mention any changes related to this problem in the change log, this update returned my R.java file and the related problems disappeared after restarting eclipse and final cleaning / restoration in the project.

+17
Jul 03 '13 at 12:01
source share

An R file cannot be generated if your layout contains errors. If your res folder is empty, then you can safely assume that there is no res/layout folder with any layouts in it, but your activity probably calls setContentView and does not find anything that qualifies as a problem with your layout.

+9
May 20 '13 at 4:29
source share

Try removing the import line import com.your.package.name.app.R , then any resource calls, such as mView= (View) mView.findViewById(R.id.resource_name); , will highlight "R" with an error, "Quick Fix" will prompt you to import R, and there will be less than two options:

  • android.R
  • your.package.name.R

Choose the R that matches your package name and you should be good to go. Hope this helps.

+4
May 20 '13 at 4:45
source share

In addition to installing the build tools and restarting the update manager, I also had to restart Eclipse in order to make this work.

+4
Jun 18 '13 at 12:56 on
source share

I had a fully working project in which I made small changes when this happened after updating the SDK. Eclipse updated the SDK and ADT, but I still could not build the project. Exlipse said there are no new updates.

The problem continued until I manually removed ADT from eclipse and installed it again. Only then will my project be built. I launched an eclipse between each step.

+1
Jun 18 '13 at 13:47
source share



All Articles