"Cannot Resolve Symbol R" in Android Studio

Android Studio “cannot resolve symbol R” but project compiles and runs

For some reason that i do not understand ,

this combination of build versions made the issue :

grade version = 4.10.1

classpath 'com.android.tools.build:gradle:3.4.0-alpha01'

when i switched to these build versions :

grade version = 4.6

classpath 'com.android.tools.build:gradle:3.2.1'

The issue was solved !

Android Studio marks R in red with error message cannot resolve symbol R, but build succeeds

Here is my temporary solution until I find a better one:

  1. Using Everything, find where R.java is created. In my case it was
    C:\Program Files (x86)\Android\android-studio\system\compiler\<project-name>.cb969c52\.generated\aapt\<module-name>.6badd9a4\production\com\<project-name>\<module-name>

  2. In the Project view, click the module and press F4. Ignore the warning.

  3. Click "+ Add Content Root" and select the aforementioned folder. Make sure it's marked in blue (as a source).

After I did this, suddenly all the warnings are gone. The problem is that if you collaborate with other people, the folder name is different on each machine so be careful when synchronizing.

Cannot resolve symbol R and nothing is working?

Try this:

  • first of all check your XML file where you are working now
    maybe there is some problem in your XML file

  • after go to in your android studio and click file menu in dropdown select invalidate cache/restart

Cannot Resolve Symbol 'R' Android Studio 3.0

Happened to me also after updating Studio and Gradle version. Even when the problem is in resource files, sometimes it might fail to indicate that. In such a scenario just close the project and import it afresh. That worked for me. The answers and comments in this question provide more details: https://stackoverflow.com/a/49537464/1877184

Error Cannot resolve symbol R only in one file

I've found out that the error with R resolving begins when the Java file is located in a subfolder of the package (for example, the ui folder).
Then Android Studio starts to import package.R.

For example, in this case:

package com.example.test3;

there is no R error. But in this one:

package com.example.test3.ui;

R is not resolved and gets autoimported.

Maybe this is the expected behaviour.



Related Topics



Leave a reply



Submit