R is unresolved


I create a new project in Android Studio and when I create a new activity for my project the IDE display me an error says this:

unresolved Reference: R

This error appear in both files in onCreate() method


I tried build, clean and rebuild the project and nothing resolve this issue.

Someone have any idea how to solve this?



Did you import R? The IDE can help import it. Just invoke one of the quick fix intentions, then import the R from your project.


Hi @fatjoe79, my project import this:

import code.diegohdez.github_api.R

where R is marked with red where says: Unresolved reference: R


also display the same error: Unresolved reference: R

I don’t know what happen.


I assume this worked before, right?

The root cause for this problem is often an error in one of your resource files (layout resource, etc). Check the output of the gradle build.


Click on Build->Clean Project and that will perform a gradle clean


R is a static class R. it created when you create resource and build it. It have all resource ID as Static for you application access all resource in your activity. This error mean you unsuccessfully build resource , please check all your resource have something Error, so R class static not created successful.