Accepted answer

this site suggests:

if you run a clean on the project it should regenerate all the generated java files, namely r.


in eclipse, under the project menu, is an option build automatically. that would help you build the file everytime modifications are made. the clean... option is also there under project.

this site suggests another solution.


don't delete these two lines from strings.xml:

android:icon="@drawable/icon" android:label="@string/app_name"




in my case, after endlessly shutting down the ide, cleaning, trying to build, etc., the issue was a "untitled folder" inside my "res" folder that i probably added there by mistake.

i wish those kind of errors would be output by eclipse, the way the ant script did:

[null] invalid resource directory name: /users/gubatron/ folder


mainly the file is relating to the .xml file and the java. we know the xml tags, but what about java, so for that we need to have an unique id for identifying the tag.

here the file is mainly related to the xml file with java for getting the values.


this problem also happened to me when i was trying to build the support4demos from the sdk source code.

after fixing some problems in the resource files (for example, "fill_parent" renamed to "match_parent") i've discovered that the problem was in the manifest file: i unchecked by trial and error the "define an <application> tag in the androidmanifest.xml" checkbox, saved the changes and the magically reappeared. then i re-checked the box, saved the file, and the was regenerated again.

i guess i came across an eclipse shortcoming.


if your androidmanifest.xml file is referencing string constants that you have stored in strings.xml, and you rename those strings in strings.xml, you'll need to change them in the manifest to make everything kosher for a build.

the same would go for any layout .xml files that are referencing those constants you changed. unfortunately, neither the markers view nor the problems view in eclipse will tell you where you need to go to fix the issues--just that they can't find as mentioned in other answers, look at the console to see where you need to fix your constant references, and then clean your project again.


  1. make sure your xml files are fine without any issues
  2. make sure your manifest has no errors in it
  3. make sure your strings have no problem in them

if any of them have issues, eclipse might fail to build the r class... fix the issues, clean & rebuild..


i encountered this problem for the first time this afternoon. even when i create a new project, isn't generated. i changed the workplace, and everything works again.


i had the same issue. turns out the reason was a few of my resources had capital letters in their filenames. i know it sounds trivial but just changing them to all small letters fixed it and retrieved my file again.

hope that helps.


almost assuredly there is something wrong with the content that would be inserted into the genfile. eclipse is not smart enough to show what the problems are or even indicate that there are problems!

think about the last edit you made to any of the xml or image content - and try to 'rollback' your changes, manually if necessary.

i find that sometimes eclipse does not like my file names for whatever reason, and i have to change them.

so add to the resources one by one assuring that it all 'works'. when something breaks, just try changing it a little bit until eclipse accepts it.

you know it's working when the genfile appears - it will do so automatically if there are no problems.


you can try one more thing.

go to c:\program files (x86)\android\android-sdk\tools>, run adb kill-server and then adb start-server. this worked for me, and i do not know the reason :-).


try checking the file. it might be the case that your android jar file in the build path doesn't match with the version mentioned over there.

it solved my problem as i had changed my target.


i had a problem with my androidmanifest.xml file and the was not generated.

i think the solution is to check all of your xml files, everywhere!


i forgot to set a name attribute on a declare-styleable tag

        <attr name="myview" format="reference"></attr>

i fixed it with

<declare-styleable name="theme">
        <attr name="myview" format="reference"></attr>

i didn't got any errors


i had the same problem.

after checking lint warnings i saw the warning the resource r.string.app_name appears to be unused..., so i deleted r.string.app_name.

this resource is required in androidmanifest.xml although lint warned me about an unused resource. i added "unused resource" to the manifest and everything went back to normal.

i hope this helps to someone.


i can't see it listed here, but i encountered the problem of my being removed and not being automatic rebuilt.

this happened to me when i was dealing with switch statements and strings. eclipse suggested that i change my projects compliance to 1.7 which promptly broke the project ( as android can't use this compliance.


[2013-03-12 17:26:33 - crimeatlas] android requires compiler compliance level 5.0 or 6.0. found '1.7' instead. please use android tools > fix project properties.

i fixed the error by using "fix project properties" and then going through the log like suggested. i commented out the xml in files mentioned replacing them temporarily with a linearlayout. when it's fixed, bam, it reappears (if "build automaticly" is on). i can then change the xml files back if there was nothing wrong.


there were no errors but three warnings where i had used hard coded text for button text attributes in my main.xml. something like this:

    android:text="scan" />

after changing text attribute to android:text="@string/scan_device" the was immediately generated.

so, it always occurs on my machine/eclipse whenever there's any error/warning in one of the xml files.

intellij idea doesn't have this problem for warnings though.


see blog post android developer tip: regenerating

rather than continuing the discovery of all the conceivable strains of the issue found in the wild, i decided to leverage the tried-and-true approach of staring at the code. having done so for a while i spotted a few red guys under the res folder. they were a leftover of my current redesign work that i was about to delete before things went awry. sure enough, as soon as i hit del on them the darn r thing automagically reappeared.

in single sentence: remove all unwanted files from the project and unwanted code from the manifest file.


solve the problem by changing the file i add a target of android-17.


if all answers fails, you can run the resource generation from command line: go into your eclipse project directory. then run

aapt.exe package -f -v -m -s res -j src -m androidmanifest.xml -i android_home/platforms/android-xxx/android.jar

just change androird_home and xxx with appropriate values. you should get on-screen information where the error is.


what also causes this is if you have a scale9 drawable with the same name as another file:

  • img_file.9.png
  • img_file.png

simply removing either one of the files fixes it.


there is also another situation that happened to me. it was when i added a string with an apostrophe in my strings.xml resource file, like

<string name="today">returns today’s date</string>

it was fixed by changing the apostrophe for another type of apostrophe, like ´.


it seems like all answers here keep repeating to check for errors in the xml and clean your project. do it! but what if that doesn't work? here's what worked for me:

if you build a project that generates a wrong r and you delete it, it won't regenerate so delete this project and create new one, make sure you do not check "build automatically" then you can copy your folders into the workspace and then you clean the project or check "build automatically" so it will generate your r properly.


in my case i checked all previous the solutions but not generated r. i just removed my main.xml file from the menu folder and regenerated it again. i don't know why, but it is working for me now...


here's one more answer that i found, after none of the previous 30 answers helped.

i found my issue in the strings.xml file, although it is very very odd. i stripped down my app to bare minimum and this was the only thing that came to light. i can even replicate it on a brand new empty app.

in the strings.xml file, this compiles (and generates the file):

<?xml version="1.0" encoding="utf-8"?>
<string name="app_name">test_my_app</string>
<string name="action_settings">settings</string>
<string name="hello_world">hello world!</string>

however, this is not:

<?xml version="1.0" encoding="utf-8"?>
<string name="hello_world">hello world</string>
<string name="app_name">my_app</string>
<string name="action_refresh">refresh</string>

the "funny" thins is that i removed the action_settings several days ago. i've cleaned my code since then and never had any issues. i added additional strings to the strings.xml file today and after cleaning the code the wheels came off. also, if i re-arrange the order of the same 3 string lines, and clean my code, the file does not get re-generated.

there's my solution to my particular issue.

i hope it helps somebody...


here's what worked for me that the other answers didn't:

  1. create new android application project,
  2. copy all files and folders from old directory (except /gen) and replace!
  3. refresh project root in package explorer.
  4. if still there, clean again!

    done. hope this helps.


if you use the lint error checker it will identify spurious import of "r". once the xml system gets hold of the wrong end of the stick all is lost!!!


first of all, check the console output.
then, check if your xml layout files names are lower-case only.
correct xml errors.
check project properties -> android for something unfamiliar


i had an error in androidmanifest.xml file, so after fixing that error and hitting


it produce me


i found a solution why r.class is not made by eclipse after making it again - 2 clean, build, etc.

the problem is here in strings.xml:

<string name="hello">hello world, helloautocomplete!</string>

<string name="app_name">helloautocomplete</string>

these are by default created by eclipse when you create projects.

definitely you are changing the strings.xml for your own requirement. sometimes you clear the string.xmls these two lines from your code:

it is making a problem in the androidmanifest.xml file:

<application android:icon="@drawable/icon"  android:label="@string/app_name">
<activity android:name=".helloautocomplete" android:label="@string/app_name">

so it can't communicate with strings.xml.


i changed my layout xml file name and found out later that of the xml file (widget provider in this case) still refers to the old layout xml which doesn't exist, and that prevented the auto generation/correction of r class.


i want to highlight 糞_爺's answer.

i had renamed a color from "listcolor" to "color_list", but i didn't catch that one of the other layouts was referencing it. so (suddenly) all of my r.string.x and r.layout.x failed on the 'r'.

eventually, i looked in the console window and looked at the errors. i thought they were all references to r not being found, but actually, one was that 'listcolor' wasn't found. as soon as i fixed that, the other errors all went away.

maybe a future version of the plugin for eclipse will allow you to rename resources in these xml files and have it propagate to all references of it.


for me, the problem was that i had an image in my res folder with an uppercase letter, that is, image.png. just put image.png.

all to lowercase and that's it!


i had the same problem. it turns out i had a circular reference; i changed a string name that was referenced in my layout.

i did a clean and rebuild and the file was not being recreated. i wasted two hours trying to figure out what was wrong. i eventually changed the layout item to some temporary text, did a clean project and the file was created.


in my case, r files were not being generated because i had xml files in my res/ folder with the same name (for example, res/layout/filename.xml and res/values/filename.xml).

after i changed one of the filenames, my r files were generated again by the build automatically option.


when nothing seems to work correctly even though you think that everything is right, check your xml files one by one. the mistake is there 100%.

if you work with the gui of the xml files everything seems ok, but when you enter textual xml files you see the mess inside. eclipse is a bit buggy for this stuff.

set buildautomatically as well, so after you fix your errors you will have your file in the generated ones.... good luck!!!


this problem just came up with me as well and unfortunately none of the suggestions here helped me. after trying a lot of things, i finally found out what happened and hope it can help others.

yesterday i downloaded a lot of new stuff using the android sdk manager. after that i updated the android eclipse plugin. today, after an eclipse "clean", the r file vanished and stopped being generated.

the reason was that, somehow, the list of available sdks (under preferences-> android) was empty. after pointing it again to the right directory it reloaded and showed the available sdks. when i closed the preferences and tried another build, everything came back to normal.

in the image attached you can see the list of sdks already filled. while the problem was happening it was empty.

i hope this can help others!

screen with sdks correctly showing


also make sure that you have the latest version of the adt plugin, and open the android sdk manager to update all sdk tools to the latest version. check for updates in eclipse itself as well. non-matching versions caused the problem for me.


my problem was inside a menu file. the compiler doesn't seem to warn you if strings which do not exist inside strings.xml are referenced in menu files. check if your items in your menu xml files reference any strings which do not exist in your strings.xml. usually in android:title.


for me, this error was caused when i tried to duplicate an existing res/menu instead of creating one with the wizard.


all of these answers could not work if you use maven. the solution for me was to add


to the configuration section of android-maven-plugin.


i've came across this problem a few times. i found that if i didn't import the package r through my application's name, for example, if my application had the package name example.test then i found that i had to import example.test.r in order to access any of the resources.

if this wasn't imported then the resources that where getting returned were the default resources with none of my own included.

with that said if you find that you are only getting a list of default resources then just check to make sure that you're importing application_package_name.r and not android.r.


there's obviously no one final answer to this, but here's another one i don't see here already:

i've had disappear after (attempting) a team synchronize, and there were conflict resolution files in the project (i.e., thingy.xml.mine,thingy.xml.r35, etc.). deleting them/resolving the conflicts regenerated r.


i had this problem. accidentally i deleted this


which started causing build errors all over the project in my xml files as well as my java files. as soon as i retyped what i deleted, it worked again :)


ok so it's clear that there can be a lot of causes for this problem. if you're on a 64 bit linux machine and you are just setting up the adt for the first time, you may get this problem where r is not automatically generating. check the console tab and you may see an error similar to:

 'no such file or directory' while attempting to get adb version from '/home/patrick/code/android-sdks/platform-tools/adb'

if that's the case you need to install ia32-libs, using something like:

 sudo apt-get install ia32-libs

see here for details: android adb not found


my problem was that appcompat was not in the same directory as my project.

i found this out when compiling my app with ant.


after reading through many posts and youtube videos, i found that each of us have missing for different reasons.

here's how i fixed this in eclipse:

  • create in gen folder manually and save.
  • after that go to project and click "clean"

the following message will display and your file will automatically be rewritten: was modified manually! reverting to generated version!


for me, i had linked v7 appcompat twice. anyhow, in eclipse, right click the project name in package explorer or navigator, go to properties, android, and uncheck any duplicates in the library section. you may need to build --> clean afterwards.


cleaning project, closing eclipse, re-opening it and launching my project finally made my to reappear... hope it helps


make sure you are not importing


score:4 will never be generated if there are any errors in the res folder. for example, in the drawable subfolder there are two files which have the same name, one is icon.png and the other is icon.html.

you can see some error in the eclipse console log window which is saying "resource entry icon is already defined.". after deleting icon.html, you can clean or just delete the gen folder. you will find that is created.


i've found that any file that has capital letters in the res folder will create this error. this happened to me with a png file i added and forgot about.


it is always helpful to take a look at the problems tab in eclipse. in my case, i was getting a "android unable to resolve target 'android-8'" error message that kept the from being generated. so, i corrected the imported target to the one i was using in the file, then i performed a clean via projects->clean and voila! is automatically generated! hope it helps!


if your os is ubuntu, i can provide some suggestion:

  1. install or upgrade ia32-lib:

    sudo apt-get upgrade ia32-libs
  2. check if you have the right permission on the aapt folder:

    cd android/adt-bundle-linux-x86_64-20130522/sdk/build-tools/android-4.2.2
    chmod 777 aapt
  3. start eclipse:

    sudo eclipse
  4. run project -> clean in eclipse


you 100% have an error in an xml-file, but the xml verification does not show you the error. this is the reason why you need to check your xml files first!


as a generalization of glaux's answer, if you have any errors in the res directory, then may not generate - even if you clean and rebuild. resolve those errors first.

as an example: when you add an image file of say, "myimage-2.jpg", the system will consider this an error, since file names are limited to alphanumeric values. do a refresh on your 'res' directory after adding any files and watch the output in your console window for any file name warnings.


if your isn't getting generated, one of the solutions is to delete the layout file named "blabla.out.xml".

after deleting this file, try cleaning the project from menu project -> clean.


i had the same issue, and i finally found the problem: in the strings.xml, i did not keep the line <string name="app_name">program-name</string> which is present by default when creating a new android project. i thought it was only used for the program helloword, which is the original program.

however, the androidmanifest.xml refers to this value, hence:

=> a compile error;
=> the isn't updated;
=> id are not recognized...


android has added in sdk build tool adt 22 for the building mechanism. you just need to do the following steps.

  1. update android sdk tool
  2. update android sdk platform tool
  3. update android sdk build tool
  4. add the path of your build tool to the path variable. (path up to---- your directory-path\android-sdk\build-tools)

this will solve the issue.


quick fix:

the package name in the manifest needs to be the same as the one in the /src folder, the /gen folder package will be automatically reproduced.

detailed observation:

observe the name of package in the /gen folder. in my case it was different than the one in the /src folder.

the package referenced in the manifest was that of the /gen folder.

i attempted to add a package with the name of the /src folder to the /gen folder too see what would've happened, but this did not solve the issue. i proceeded then to remove the package name that was not the same as the package name of the /src folder. this package with the name that did not correspond to the /src folder was recreated as soon as i removed it.

since the package reference in the manifest corresponded to the one that was being senselessly recreated and that did not correspond with the package in the /src folder, this prompted to rename package = "oldpackage" with the package = "srcfolderpackage".


in eclipse, simply use project --> clean to clean the project. the is going to be automaticly (re)-created.

if for some reason that dosn't work: make sure your layout.xml files don't contains errors. eclipse seems to be a bit buggy here: sometimes it doesn't mark the errors within the xml nor the package explorer. in such a case: take a look at the "console" or "problems" view after using "clean". all errors should be displayed there. fix them and redo a clean.

note: it is not neccessary to fix the errors you get because of a missing r file! just fix the xml files and other project errors and use clean!


one reason the r.class can go missing suddenly is when there are errors in you xml files. for instance, when you add an xml file with uppercase letters in the name like mycoollayout.xml which is not allowed. or when you have references that don't point to existing files, etc.


i had the same issue. when i checked it out i found that the name of the xml resource under layout was not having the correct naming convention. it had some capital letters. so i renamed it to make all letters lowercase and the magic worked.


i found this happening to me with a broken layout and everything blows up. relax, it's like that old mistake when you first learned programming c where you forget one semicolon and it generates a hundred errors. many panic, press all the buttons, and makes things worse.


  • make sure that anything the r. links to is not broken. fix all errors in your xml files. if anything in the adks are broken, r will not regenerate.
  • if you somehow hit something and created import android.r in your activity, remove it.
  • run project -> clean. this will delete and regenerate r and buildconfig.
  • make sure project -> build automatically is ticked. if not, build it manually via menu -> project -> build project .
  • wait a few seconds for the errors to disappear.
  • if it doesn't work, delete everything inside the /gen/ folder
  • if it still doesn't work, try right-clicking your project -> android tools -> fix project properties.
  • check your *.properties files (in the root folder of your app folder) and make sure that the links in there are not broken.
  • right-click your project > properties > android. look at the project build target and library sections on the right side of the page. your build target should match the target in your androidmanifest.xml. so if it's set to target 17 in androidmanifest, make sure that the target name is android 4.2. if your library has an x under the reference, remove and re-add the library until there's a green tick. this might happen if you've moved a few files and folders around.

what to do if r doesn't regenerate

this usually happens when you have a broken xml file.

  • check errors inside your xml files, mainly within the /res/ folder
  • common places are /layout/ and /values/, especially if you've changed one of them recently
  • check androidmanifest.xml. i find that often i change a string and forget to change the string name from androidmanifest.xml.
  • check that android sdk build-tools is installed. window -> android sdk manager -> tools -> android sdk build-tools
  • make sure when you update the android sdk tools, you also update the android sdk platform-tools and android adk build-tools. build fails silently if they don't match.
  • if you can't find the issue, right click /gen/ -> restore from local history... -> tick -> click restore. even if it doesn't solve the problem, it will clear out the extra errors to make the problem easier to find.

Related Query

More Query from same tag