# R is unresolved

**URL:** <https://discuss.kotlinlang.org/t/r-is-unresolved/9345>\
**Category:** Android\
**Created:** [September 7, 2018, 1:03am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345 "2018-09-07T01:03:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![diegohdez90](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@diegohdez90](https://discuss.kotlinlang.org/u/diegohdez90)\
**Post date:** [September 7, 2018, 1:03am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/1 "2018-09-07T01:03:00Z")

</div>

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

`setContentView(R.layout.activity_main)`

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

Someone have any idea how to solve this?

Thanks.

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [September 7, 2018, 6:44am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/2 "2018-09-07T06:44:55Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![diegohdez90](https://avatars.discourse-cdn.com/v4/letter/d/71c47a/32.png) [@diegohdez90](https://discuss.kotlinlang.org/u/diegohdez90)\
**Post date:** [September 7, 2018, 2:29pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/3 "2018-09-07T14:29:02Z")

</div>

Hi @fatjoe79, my project import this:

```auto
import code.diegohdez.github_api.R

```

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

```auto
setContentView(R.layout.activity_get_token)

```

also display the same error: `Unresolved reference: R`

I don’t know what happen.

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [September 7, 2018, 3:29pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/4 "2018-09-07T15:29:36Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mohamedebrahim96](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/mohamedebrahim96/32/5493_2.png) [@mohamedebrahim96](https://discuss.kotlinlang.org/u/mohamedebrahim96)\
**Post date:** [September 10, 2018, 8:05am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/5 "2018-09-10T08:05:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nemo](https://avatars.discourse-cdn.com/v4/letter/n/f07891/32.png) [@nemo](https://discuss.kotlinlang.org/u/nemo)\
**Post date:** [September 14, 2018, 1:39am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/6 "2018-09-14T01:39:38Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vn1miguel](https://avatars.discourse-cdn.com/v4/letter/v/e495f1/32.png) [@vn1miguel](https://discuss.kotlinlang.org/u/vn1miguel)\
**Post date:** [October 2, 2018, 10:06pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/7 "2018-10-02T22:06:32Z")

</div>

If you have a warning in your project please fix it.  
I tried almost everything on web, but only worked when I fix the gradle’s warn, in my project

---

<div class="post-metadata">

**Author:** ![sharansalian](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/sharansalian/32/5564_2.png) [@sharansalian](https://discuss.kotlinlang.org/u/sharansalian)\
**Post date:** [October 3, 2018, 8:52pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/8 "2018-10-03T20:52:49Z")

</div>

Solution:

1. Grade Sync.
2. Invalidate caches and restart.
3. Clean the project and rebuild.
4. Alt + Enter import R files.

🙂

---

<div class="post-metadata">

**Author:** ![CurtesMalteser](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CurtesMalteser](https://discuss.kotlinlang.org/u/CurtesMalteser)\
**Post date:** [October 11, 2018, 7:20pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/9 "2018-10-11T19:20:59Z")

</div>

I’m also facing this issue.  
Gradle Sync or Invalidate caches doesn’t work at all and the import is not available for autocomplete.  
If I type the package, even if the R is red, the project compiles and runs.  
This is just boring for now.  
This error for me started when I installed Android Studio 3.2 and Kotlin 1.71.  
Good tips are welcome.

---

<div class="post-metadata">

**Author:** ![cnkaptan](https://avatars.discourse-cdn.com/v4/letter/c/e47774/32.png) [@cnkaptan](https://discuss.kotlinlang.org/u/cnkaptan)\
**Post date:** [October 12, 2018, 7:51am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/10 "2018-10-12T07:51:26Z")

</div>

Same as me, so annoying, i tried everything but it is not generating

---

<div class="post-metadata">

**Author:** ![CurtesMalteser](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CurtesMalteser](https://discuss.kotlinlang.org/u/CurtesMalteser)\
**Post date:** [October 12, 2018, 7:57am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/11 "2018-10-12T07:57:01Z")

</div>

On my case, it might be related with not very well supported libraries I have on my project and that are not necessarily updated, also don’t have Kotlin support. Anyway, when I checkout commits previous to this change, everything compiles properly and class R is generated.  
But this libraries are absolutely essential to my project and the work the creators of this libraries have been awesome, Hope this can help and give some clues to solve this issue.

---

<div class="post-metadata">

**Author:** ![benkidd](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@benkidd](https://discuss.kotlinlang.org/u/benkidd)\
**Post date:** [October 15, 2018, 1:00pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/12 "2018-10-15T13:00:03Z")

</div>

I was having the same problem recently, and this turned out to be an issue with the latest Android Gradle plugin alpha (3.3.0-alpha-13).  
Switching back to the previous version solved the problem.  
Hope this helps.

---

<div class="post-metadata">

**Author:** ![Mes.Inc](https://avatars.discourse-cdn.com/v4/letter/m/a8b319/32.png) [@Mes.Inc](https://discuss.kotlinlang.org/u/Mes.Inc)\
**Post date:** [October 17, 2018, 8:28am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/13 "2018-10-17T08:28:24Z")

</div>

Have had the same issue too, had to use a stable gradle plugin for R to be resolved.

---

<div class="post-metadata">

**Author:** ![CurtesMalteser](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@CurtesMalteser](https://discuss.kotlinlang.org/u/CurtesMalteser)\
**Post date:** [October 25, 2018, 7:27pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/14 "2018-10-25T19:27:09Z")

</div>

This solved my issue.  
Thanks!  
After checking my git commits I noticed that when I accepted the suggestion to update Kotlin to version 1.71 I also accepted the update for Android Gradle plugin 3.3.0-alpha-13.  
I switched to 3.2.1 and the error was there anyway.  
Like I mentioned in a previous post, the error comes from a library that uses the same library that I use, but the version on my project was a lower version.  
After update the dependency version, the error has gone.  
The difference from the version 3.3.0-alpha-13 to 3.2.1, is that the first one (for some reason) was not showing the error in the Logcat and the second yes.  
This change made the fix possible.  
So the error was unrelated with Kotlin on my case.

---

<div class="post-metadata">

**Author:** ![igor\_ganapolsky](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/igor_ganapolsky/32/5705_2.png) [@igor\_ganapolsky](https://discuss.kotlinlang.org/u/igor_ganapolsky)\
**Post date:** [November 5, 2018, 10:59am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/15 "2018-11-05T10:59:37Z")

</div>

Wouldn’t Android Studio auto-import these?

---

<div class="post-metadata">

**Author:** ![fatjoe79](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/fatjoe79/32/4221_2.png) [@fatjoe79](https://discuss.kotlinlang.org/u/fatjoe79)\
**Post date:** [November 5, 2018, 11:30am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/16 "2018-11-05T11:30:35Z")

</div>

It depends on how you use the editor. But yeah, importing was not the problem in this case.

---

<div class="post-metadata">

**Author:** ![abhisonawane126](https://avatars.discourse-cdn.com/v4/letter/a/ee7513/32.png) [@abhisonawane126](https://discuss.kotlinlang.org/u/abhisonawane126)\
**Post date:** [November 29, 2018, 3:17pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/17 "2018-11-29T15:17:41Z")

</div>

I got same error: R unresolved, when trying to link two activities.  
I followed the Warnings and suggestions by IDE red marking in .xml file AND resolved the error.

actual error was in the fontFamily . I Changed the fontFamily and debug the app (shift+F9) , ERROR resolved

---

<div class="post-metadata">

**Author:** ![cairomenso](https://avatars.discourse-cdn.com/v4/letter/c/6a8cbe/32.png) [@cairomenso](https://discuss.kotlinlang.org/u/cairomenso)\
**Post date:** [December 22, 2018, 8:49pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/18 "2018-12-22T20:49:17Z")

</div>

Hi everyone.  
I am a noob, just beginning to learn programming languages. So, read with caution.  
I faced the same problem after running the project successfully many times. After all I discovered it was just a typo in one xml file. I put some number into a tag, without noticing. After remove it, the R problem disappeared.  
As “nemo” said above, R is a static class that works using the xml code. If xml is wrong, R will not be correctly built.

---

<div class="post-metadata">

**Author:** ![ahmad](https://avatars.discourse-cdn.com/v4/letter/a/a4c791/32.png) [@ahmad](https://discuss.kotlinlang.org/u/ahmad)\
**Post date:** [December 26, 2018, 9:32am UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/19 "2018-12-26T09:32:54Z")

</div>

Hello,  
I also had same problem and resolved it by followup my layout resources in code view. I had drag a button and use ‘&’ sign in button’s name. I’d just replace ‘&’ to ‘and’. This ```  
unresolved Reference: R , usually come from layout. You should see your layout resource in code view.

---

<div class="post-metadata">

**Author:** ![lmorda81](https://avatars.discourse-cdn.com/v4/letter/l/2bfe46/32.png) [@lmorda81](https://discuss.kotlinlang.org/u/lmorda81)\
**Post date:** [January 22, 2019, 4:42pm UTC](https://discuss.kotlinlang.org/t/r-is-unresolved/9345/20 "2019-01-22T16:42:25Z")

</div>

I also had to switch Android gradle plugin back to 3.2.1 from stable 3.3.0, using Kotlin version 1.3.0 here

[Next page](https://discuss.kotlinlang.org/t/r-is-unresolved/9345.md?page=2)
