"cannot resolve symbol R" in Android Studio

In every instance in all of my classes where I reference R.id.something , the R is in red and it says "cannot resolve symbol R". Also every time there is R.layout.something it is underlined in red and says "cannot resolve method setContentView(?)". The project always builds fine. It is annoying to see this all the time. I have read many other questions on here about something similar but most involved importing projects from eclipse. I am using what I believe to be the most recent version of android studio and the project was created with android studio and worked without any cannot resolve R problems. I would like to know what causes this if anyone knows.

UPDATE : Solution: At the time android studio was brand new and I was also a brand new developer. I should never had been using android studio, I never realized how unfinished it was. Thanks everyone for the support in trying to help since this has been posted. Ironically the actual answer to this question has been deleted and cannot be undeleted. I feel that my original answer is the solution to this problem.

My original answer that was deleted:

I think I have figured out the issue. The issue is with Android Studio, every time I added the admob library all these errors started. All my other projects without ads don't have similar issues. I'm now using Intelij and staying away from Android Studio


I had this this issue too. A simple 'gradlew clean' and 'gradlew build' did the trick.


Click on Build->Clean Project and that will perform a gradle clean


In the latest versions of Android Studio, at least for me, the following works:

"Tools" -> "Android" -> "Sync Project with Gradle Files"


I have similar problem and here is what I did:

clean project and Sync Project with Gradle ,

在这里输入图像描述

check buildTools version in my sdk 在这里输入图像描述

From build gradle (module ) change minSdkVersion from 8 to 9

defaultConfig {
        applicationId "PackageName"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }

But all this didn't help.

Finally I found the answer (this worked in my case)

Change from build.gradle(module:app)

android {
    compileSdkVersion 21
    buildToolsVersion '21.0.1'
......
....
}

Or

select File | Project Structure change Build Tools Version to 21.1.1

在这里输入图像描述

链接地址: http://www.djcxy.com/p/23690.html

上一篇: 如何使用复选框将所选行中的数据从JSP传递到服务器

下一篇: Android Studio中的“无法解析符号R”