R is unresolved

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

Solution:

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

:slightly_smiling_face:

4 Likes

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.

2 Likes

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

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.

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.

3 Likes

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

1 Like

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.

1 Like

Wouldn’t Android Studio auto-import these?

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

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

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.

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.

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

3 Likes

Same issue here, only thing that worked was to update Android Studio to 3.4 RC2

Thanks a lot for the info! This solved my problem!
:grin: :clinking_glasses:

1 Like

Try to check your applicationId in build.gradle and package attribute in your manifest.

1 Like

Thanks a lot for this! This solved my problem!

1 Like

I have to say that God sent you to save my life :))))

1 Like

Having the same error in Android studio chipmuk in Mac.
And suggesting to implement the ‘app’ in androidTestImplementation in dependancies as
androidTestImplementation project(path: ‘:app’)

This solves the issue and test cases passed, but I am sure this is not the right fix, since I don’t remember I have added this line in my gradle earlier in Linux machines. And this implementation may cause a recursive implementation because the “androidTest” is already in the “app” folder, and now we imoplement the “app” inside “androidTestImplementation” looks confusing. anyhow tests works.

1 Like