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.
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.
- 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.
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
- OR direct click on the icon -> Sync project with Gradle
Still not working check the Gradle Version and update to the latest one.
It can be a problem of “cannot resolve symbol r android studio“, let try this also.
- File -> Invalidate caches and restart.
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:
A lower or upgrade version of any library can make
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
- Click on “Build” and click on “Rebuild Project”
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