Android Studio marks R in red with error message "cannot resolve symbol R", but build succeeds
Just Click on Build -> Rebuild Project option in your Android Studio.
I found that this issue was caused because I had errors in my XML files. Once you fix the XML errors, do a clean/build, it fixed the issue.
Click on Build -> Rebuild Project
and then
click Tools -> Android -> Sync Project with Gradle Files
.