Android Studio Suddenly Cannot Resolve Symbol R


Answer :

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.


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.


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.


Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable