Cannot resolve symbol r | Android Studio

Not only you, but many programmers are also facing a “cannot resolve symbol r” error in Android app development. An “r” turns red and can’t run the Application and throw the error in “logcat”. This problem has faced mostly the time when you shift your code to another Computer or send the code to another person.

Cannot resolve symbol r Android Studio

Where the letter R stands for the Resource. This error occurs because of the incapability of the build process to Sync Resource files with your projects. Usually, this happens because of the improper build of the project.

Solutions of Android resolve symbol r

There are many ways to remove error “cannot resolve symbol r“, Here are some:-

  • XML File – there is a problem with your XML.
  • Gradle Files – Not proper sync or different version.
  • Caching –  Invalidate caches
  • Package name – Changed the package name.
  • Libraries/Modules – Downgrade some libraries which make resource conflict.
  • Lowered compileSdkVersion and targetSdkVersion
  • OLD Android Studio
  • Clean and Rebuild Project

Let’s Solve the Error – “cannot resolve symbol r”

We will look at a solution for it one by one with a step. Chances are any one of them will solve it.

XML File

If your resource file XML file even minor miscoded then you will face this problem. Check your resource layout and other XML. Android Studio turns this file into a red color. Then check the file and code of it where is the problem.

The Gradle Files Sync

Try the sync Gradle, may this solve the “cannot resolve symbol android studio“. Follow this step:-

  • Toolbar -> File -> Sync project with Gradle
Sync project with gradle option to resolve symbol r
  • OR direct click on the icon -> Sync project with Gradle
Sync project with gradle

Note: A Screenshot is from Mac OS, so there is chances position of button and icon change in Linux, Windows, and another os.

Still not working check the Gradle Version and update to the latest one.

Caching

It can be a problem of “cannot resolve symbol r android studio“, let try this also.

  • File -> Invalidate caches and restart.
Invalidate caches and restart

Package name

This is a very common mistake done by a developer changing a package name in manifest or change class location package. Let’s see what if I change if the package in the AndroidManifest.xml.

Changing -> com.eyehunts.myapplication to com.eyehunts.a.myapplication

Output and code structures:

package name to resolve symbol r

Libraries/Modules

A lower or upgrade version of any library can make generate this error. To prevent r error in android, check Module Grable and your project SDK and target version.

OLD Android Studio

Recently I face this cannot resolve symbol r issue, I tried all the ways mentioned in this tutorial. In the last, I did update my Android studio and the problem was solved.

You can check your Android studio version and update it:-

  • Click -> Android Studio -> Check for updates …
  • If update available -> Click -> Update & restart.
  • If delete old version option came after installation new patch, then do delete all. It’s just taking space in your computer hard disk.

Clean and Rebuild Project

Last but can be the first option to do solve error –can not resolve symbol r.

Almost everyone suggests this process. It may work if there is no package, version, Gradle version, SDK version, etc problem.

Let’s see step to do it:-

  • Click on Build -> Clean project
Clean project android studio
  • Click on “Build” and click on “Rebuild Project”
Rebuild Project android studio

If still facing the issue – “How to solve cannot resolve symbol r in the Android Studio“, then comment in below. And any other solution you have, then comment. We will update this tutorial.

Note: This example (Project) is developed in Android Studio 3.3.2. Tested on Android 9 ( Android-P), compile SDK version API 28: Android 9.0 (Pie)

Coding in Java and kotlin


11 thoughts on “Cannot resolve symbol r | Android Studio

  1. I have tried everything you have suggested. I KNOW it’s gradle, because whenever I have a non-coding error it’s ALWAYS gradle. I googled for hours, and I cannot find the solution to this:

    how do I MANUALLY import that R library into my project and FORCE gradle to find it at an ABSOLUTE path? then it will shutup and compile my java code which is error free.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.