Cannot resolve symbol 'R'
In the source code, it will show all usage of R as red in colour.
From what I know, here are two situations that cause this error to appear.
- Copy of a source file into the project. This include copying of Modules from another existing project.
- During one of the build, there was a problem
SolutionThis is how I did it on Android Studio 3.1.2.
Step 1: Rebuild the project.Open the Java files that was just copied or the problematic files. Remove any reference of import to the 'R'. In the manifest/AndroidManifest.xml, correct the package name if it is not the same as the current project.
On the Menu bar click Build ->Clean Project.
Step 2: Sync files in the project.On the Menu bar click Files ->Sync Project with Gradle Files. Close and restart Android Studio.
Works all the time.