r can not be resolved to a variable elipse

This question already has an answer here:

  • Developing for Android in Eclipse: R.java not regenerating 62 answers

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?


Dont worry. First you may clean the project, then run the project. If this does not work then follow the following links:

If Clean/Rebuild Project doesn't work try to check our package name in AndroidManifest.xml.

The problem "R cannot be resolved" happens when you change your package name in the AndroidManifest.xml file. It uses your Android package name to create a subdirectory under the "gen" directory where it stores the R.java file.

For me the error got fixed by making some changes in Android SDK Manager.
Whatever be the latest API level available, install its "SDK Platform". For me latest API level available was 16, so I installed its's SDK Platform as shown in the image below. It works fine now.

r can not be resolved to a variable elipse

Cheers, Mayank

Did you just update both sdk and adt(from 21 to 22), then you need to install a new item: Android SDK Build-tools

Refer to: Eclipse giving error, missing R.java file after recent update

For me somehow the Project properties; Android; Project Build Target was not set. I chose a Android version there (e.g. 4.2) and it fixed it.

For me, there was a missing slash at the end of my SDK. In Eclipse > Preferences > Android > SDK Location

For example, change




for me, the best solution to suggest to people that have problems with the "R" file would be to try the next steps (order doesn't matter) :

  1. update ADT & SDK , Eclipse and Java.
  2. remove gen folder , and create it again .
  3. do a clean-project.
  4. right click the project and choose android-tools -> fix-project-properties .
  5. right click the project and choose properties -> java-build-path -> order-and-export. make sure the order is :
    • Android 4.3 (always the latest version)
    • Android private libraries
    • android dependencies
    • your library project/s if needed
    • yourAppProject/gen
    • yourAppProject/src
  6. make sure all files in the res folder's subfolders have names that are ok : only lowercase letters, digits and underscore ("_") .
  7. always make sure the targetSdk is pointed to the latest API (currently 18) , and set it in the project.properties file

I got similar problem and solution I found out was in resources any of the file aka background, sound etc must not contain capital letters or any special symbol other than _

What you really need to do it just install "build-tools" from sdk manager, and r.java will be generated automatically.

Sometimes you can accidentially add an import to "R", so if at the top of your code you see some weird import about that that you did not add yourself, delete the reference, and everything should go back to normal

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.

Check the androidmanifest.xml file and layoutfolder xml files. They should be created properly as the starting and ending clause in xml should be placed properly. Update the files, clean and build. And all set!

I had this problem and none of the other guides helped, and then I realized I didn't have the java jdk installed on my system. If you haven't done this either go download the version corresponding to the version of eclipse you installed (x86 or x64)

It is possible you have an error in your *.xml files: layouts and etc.

I had the same error. Error was that, I had placed a file in res/raw folder with invalid filename. As soon as I corrected the file name to a valid one, error was resolved!

Allowed characters for naming a file:-

1. a-z
2. . _
3. 0-9
4. no capital letters

Capital letters were the issue in my case!

your android manifest must start with correct package

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="HERE - Correct package NAME"
    android:versionName="1.0" >`

Project > Clean...

usually regenerates R.java file located in gen/com.mypackage

In my case, R.java wasn't getting generated because of a hierarchical parent error, which in turn was cured by updated one or more Eclipse plugins (Go Eclipse-->Help-->Check for Updates)

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.

Try to modify AndroidManifest file.

For example add space and delete this space. After this OPERATION, save project. Resources will be refreshed. It can help.

I solved the problem with resolving R resource on fc19.x86_64 and ADT v22.0.5-757759 by installing additional libraries after Fedora and ADT upgrade.

yum install ld-linux.so.2
yum install libstdc++.so.6
yum install libz.so.1

Those libraries are required by adb (Android Debug Bridge version 1.0.31).

Then restart Eclipse and perform project clean Project->Clean check project you would like to clean.

Hope it helps :)

I found this problem when trying to run the Notepadv3 programme from Googles 'first lesson'..

For me it was an issue with the xml file, due to the API level I was using. I renamed each case of Match_Parent to the older type of Fill_Parent. Oh and if you have already auto-built the project then you need to delete 'import android.R' on NoteEdit.java and Notepadv3.java, clean the project (click 'Project', then 'clean...') before saving.

Solved it for me. Came from this post Android NDK r4 san-angeles problem

Can't believe Google dosen't warn of this problem - I have been setting up another PC to start programming again and even with a bit of prior knowledge this was a pain.. How do you set the API when importing an existing project??? Can't see where there is any dialogue option when you 'File' 'Import' etc ..


Problem was eclipse was not generating R.java. To resolve this issue please go to project->clean... and select your project and select ok and then clean and build project and import your package name R file(Ex com.demo.R). It works.

This can happen when the android naming convention isn't followed. Check if you have placed a file/photo into one of the android folders and make sure that the file name contains only lower case letters

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.

I got this when I renamed a project. Although the project is renamed, some references are not. Clearing lint, and then rerunning lint helped. (Right click project > Android Tools > Clear Lint Markers, then Run Lint)

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 been having this and i did trace it back to the layout files.. It happend to me again however i could not find noting in the layout files. I looked in the string.xml and there was it.. one of the string names started with cap and that was causing the problem.

Remove any XML files in the /res/menu folder.

Category: android Time: 2011-10-19 Views: 1

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development


Front-end development


development tools

Open Platform

Javascript development

.NET development

cloud computing


Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.109 (s). 12 q(s)