Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Android Studio displays in all java files in red : “cannot resolve symbol R” but the project compiles and runs.

I have tried every solution here: Android Studio "cannot resolve symbol" but project compiles and works, but with no luck.

I tried to :

  • invalidate caches and restart android studio

  • delete .gradle and .idea folders

  • clean and rebuild the project

  • install a new version of android studio

  • mess up with gradle file then undo changes and sync project

One thing that I want to try, but I don't know how to achieve, is to reopen the project from scratch as I was opening it for the first time, but I don't know how to do this.

I also tried answers from here: Android Studio says "cannot resolve symbol" but project compiles, but again with no luck.

Android studio version = 3.2.1

dependency versions in gradle project file:

classpath 'com.android.tools.build:gradle:3.4.0-alpha01'
classpath 'com.google.gms:google-services:4.0.0'
like image 764
user2469133 Avatar asked Nov 18 '18 11:11

user2469133


People also ask

What is r in Android Studio?

R is a class containing the definitions for all resources of a particular application package. It is in the namespace of the application package. For example, if you say in your manifest your package name is com. foo. bar , an R class is generated with the symbols of all your resources in com.

Where is the R file in Android Studio?

R. java is the generated file by ADT or Android studio. It will be located under app\build\generated\source\r directory.

What does Cannot resolve symbol mean in Java?

In JavaLanguage, if you get 'cannot resolve symbol', you have used a name that the compiler hasn't recognized. Class names -- If it is a class name, the compiler cannot find the class.


1 Answers

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 !

like image 155
user2469133 Avatar answered Nov 09 '22 13:11

user2469133