Home » Android » android – No R class is generated

android – No R class is generated

Posted by: admin June 15, 2020 Leave a comment


The automatic generation of the R class does not work anymore.
I have tried Project -> Clean…
A warning on all xml files has also showed up: “No grammar constraints (DTD or XML schema) detected for the document.” Maybe that is why the code generation have stoped.
Any idea how to get the R class generated again?

How to&Answers:

The R file will not be generated unless there are not error in the /res/ folder.

If there are not errors in the /res/ folder, try removing the gen folder and then right click on the project -> android -> fix android settings.


As the other posts say, the /res folder mustn’t have any files that have errors in them. If so then the R.class file cannot be generated. If the errors are fixed then the project should re-build and the R.class should generate. If not, I believe you can right-click on the project then Android Tools -> Fix Project Properties. I think that is what @Macarse was meaning by project -> android -> fix android settings. I didn’t see those options but the Android Tools -> Fix Project Properties usually does the trick for me or sometimes cleaning the source works too (Right-click the project -> Source -> Clean up…).

Hope this helps you.




Generally when you get this kind of error, that means that you have an error in one of your resources. Have you added a drawable, changed a layout, or added/modified any resource just before this happens?
For instance if you created a 9-patch drawable, you can’t have the image.png and image.9.png at the same time in the drawable folder, it will create an error, and Eclipse will go crazy. Same thing If you made a mistake in a xml file, and saved it. Then the R class can’t be generated as long as you have not corrected the file.


In my case it was so simple as defining the sdk location ending with a slash. The problem was that it wasn’t finding appt.exe because it was looking for it in ../sdkplatform-tools/aapt.exe instead in ../sdk/platform-tools/aapt.exe


Here is your solution:

Open a terminal window and type

sudo apt-get install ia32-libs

even if you are using a 64-bit os, this will again help you. It worked perfectly for me.


While it’s true that R won’t be generated if there are errors in your resources, I’ve found that the problem is that Eclipse doesn’t always report errors.

Do this in your project directory:

android update project -p .

and then build from the command line. See if that comes up with any useful errors.


Also this can happen because of one of the folders are named wrong, and so compromising the android directory structure. In my case, I tried to generate the class R in many ways I saw here until I realized I had created a folder “res / drawble” instead of “res / drawable”. Like magic, you just go to Project-> Clean with “Build Automatically” checked and it appeared.


I use Intellij IDEA and some day R class stopped generating (maybe, after update).

Setting “External build” checkmark in compiler preferences fixes the problem:

enter image description here


I have the answer, in my case where my R class could not be detected by the src class. Just make sure that the name of the package where the R class is located (appname -> gen-> package-> R.class Is the same than the one you are actually using in your src Activity class.