-1

Every once in a while I get Cannot resolve symbol 'R', on a random project, and nothing seems to fix that. Of course I tried the following procedure: “cannot resolve symbol R” in Android Studio. But even invalidating caches or rebuilding the project didn't work.

Any other causes for this? And how to fix that?

pileup
  • 1
  • 2
  • 18
  • 45
  • update your sdk manager – sasikumar Nov 22 '18 at 09:55
  • might be a problem in one of your layout files (e.g. typos like textView instead of TextView, or custom Views with the wrong package name) . the IDE will fail to generate the R files if any of the resources files have a problem. you can go check your latest changes by reviewing the Local History in your RES folder. – Angel Koh Nov 22 '18 at 09:58

4 Answers4

1

Please try the following:

  1. File -> Synch Project with Gradle Files
  2. Build -> Clean Project
  3. Build -> Rebuild Project
  4. Gradle from the right pane -> MyAppName -> :app -> Tasks -> build -> clean enter image description here
  5. Left Project Navigation pane (Android view) -> build.grade (Module:app) -> Update the version of appcompat & design support dependencies to the recent version by ALT + ENTER on each of them
  6. File -> Invalidate Caches / Restart
  7. Upgrade to the latest android studio
Zain
  • 37,492
  • 7
  • 60
  • 84
0

Usually this error occurs when you have some error in your layout or any other resource file.

  • Just recall if you have changed any of the resource file (layout, strings, color etc). And see if you find error in any of these file.

  • You can also check your manifest file and see if it gives you any error.

  • Clean your project, rebuild, restart Android Studio and check again.

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22
Maniya Joe
  • 761
  • 6
  • 24
  • None of the resources files gives me an error. The manifest is also clean. Not sure what to do now – pileup Nov 22 '18 at 10:39
  • I found out the problem, I am using Firebase and it automatically added the line `apply plugin: 'com.google.gms.google-services'`, now I removed it and it works. But won't that damage any other part of the code that I yet to know? – pileup Nov 22 '18 at 10:54
  • When using firebase with `apply plugin: 'com.google.gms.google-services'`, you must add `classpath 'com.google.gms:google-services:4.2.0'` in the gradle file at the project root, otherwise, you get other error with gradle. See the firebase configuration for Android. – Juky Nov 22 '18 at 14:33
0

Go to Android Studio -> File -> Invalidate Caches / Restart...

0

Check layout_width and layout_height on your various components. When I had a number as opposed to match_constraint or wrap_content, I failed to add "dp" afterwards, and the number wasn't compatible with the dimension. Stupid mistake, but adding dp fixed the R problem for me.

ppreetikaa
  • 1,149
  • 2
  • 15
  • 22
GMR
  • 1