Android studio suddenly cannot resolve symbol R

Downgrade Your Gradle Plugin Version

No amount of cleaning, rebuilding and restarting would do the trick for me.

The only thing that did the trick was downgrade our Gradle version from 3.4.0-alpha02 to 3.2.1.

So, instead of:

dependencies {
    classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
}

We used:

dependencies {
    classpath 'com.android.tools.build:gradle:3.2.1'
}

After making that change and then doing a Gradle sync, everything worked.

Not sure if it's related to the alpha release or to that version or if changing your Gradle version at all just forces a refresh that otherwise cannot be done with the other commands, but there ya go.


Most of the time it is due to a bad XML file. XML files can be layout files, value files, or the Manifest file. Please check your xml files and try to rebuild the project. Sometimes cleaning the project and rebuilding it also works.


Make sure in your AndroidManifest.xml the package name is correct. That fixed the problem for me when my R.whatever was marked red!


In addition, make sure you do not have a drawable with an invalid name. I had a drawable with a numeric filename and that didn't sit well with Android so it failed to compile R.java.