67

I upgraded Android Studio today to 3.1, and now Android Studio says it cannot resolve symbols for most of the resources (for example ThemeOverlay in styles.xml or ?attr/actionBarSize). This doesn't seem to prevent me from building or running in an emulator so far, but these errors are making me nervous.

Has anyone else experienced this issue? How can I go about resolving it? I have tried syncing gradle and cleaning my project but it doesn't seem to help at all.

Any ideas?

I'm using Android Studio 3.1 with Gradle version 4.4 and Gradle Plugin 3.1.0

EDIT: This issue affects updating to Android Studio 3.1.1, 3.1.2, 3.1.3, 3.1.4 as well as Gradle Plugin to 3.1.1, 3.1.2, 3.1.3, and 3.1.4. However, the answer below still works.

JPM
  • 1,482
  • 5
  • 18
  • 25

16 Answers16

166

Close the project and import it again. Worked for me today.

import project

Ashraf Amin
  • 343
  • 3
  • 7
marko
  • 1,819
  • 1
  • 8
  • 11
  • 63
    Invalidating caches, manually deleting gradle caches, and other tricks did not work. Closing project and importing it again worked. Wow! I'm looking forward to Android Studio 4.0. Maybe it'll burn down my house – BenjaminButton Mar 28 '18 at 15:05
  • 7
    Open an existing Android Studio project also works in Welcome to Android Studio. – Andy Sander Mar 29 '18 at 05:08
  • 3
    I closed and reopened project as existing Android Studio project (did not import it), and it worked! – Andrew Glukhoff Mar 29 '18 at 08:34
  • For those of you that don't want to reimport a project, the solution that worked for me is here: https://stackoverflow.com/questions/49520097/android-studio-3-1-cannot-resolve-symbol-theme – N Dorigatti Mar 29 '18 at 10:18
  • 1
    FYI I updated Android Studio from 3.1 to 3.1.1 and the problem reappeared. However this answer still works so I updated the post. – JPM Apr 10 '18 at 14:10
  • I saw this initially and thought it is no different than Invalidating caches and I tried different solutions for 2 hours none of them worked, finally, I gave it a try thinking it will never work but BOOM it worked. Why Are you doing this to me, God? – Sai Apr 22 '18 at 14:27
  • What the..? I wasted hours on this issue, tried every possible fix and this was the solution? I think Google should just admit at this point that they have failed miserably with AS. – Zuhaib Ahmad Apr 26 '18 at 04:49
  • 11
    WHY DOES THIS WORK?! – AndrewPK Apr 26 '18 at 21:14
  • Wooowww i don't know why its worked but thank you so much. – RushDroid Jun 26 '18 at 11:55
  • Note that u must open it not from Recent projects but from choosing the location of project – Saman Sattari Aug 04 '18 at 06:22
  • I can confirm that this eventually worked also on AS `3.2.2`. I tried it a few times, but problem didn't go away. Then a few hours later, and now it works. There is definitely some cache or background process problems somewhere. I was just about to remove my entire AS installation, when I thought to come back here and read again. Make sure you delete the item in the "old" list, before re-importing. In addition I double-clicked on the folder to get to the root dir, then `ok`. (To AS devs: please add a cache cleaning procedure. AS + Gradle is currently poisoning the system with artifacts.) – not2qubit Apr 03 '19 at 23:05
20

The support library is out of sync.

This error happens because the support library gets out of sync with your project. To get it back in sync you can do the following steps:

  1. Open your app module's build.gradle file
  2. Comment out the implementation lines for the support library. For me it looks like this:

    //implementation 'com.android.support:appcompat-v7:27.1.1'
    //implementation 'com.android.support:recyclerview-v7:27.1.1'
    //implementation 'com.android.support.constraint:constraint-la
    
  3. Sync your project with gradle. You will have some errors now. Don't worry about that.

  4. Uncomment the implementation lines that you previously commented out.

    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:recyclerview-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-la
    
  5. Sync your project with gradle again.

The "Cannot Resolve Symbol" error should be gone now. This has worked for me several times on different projects.

Note

  • If your project has multiple modules, then you need to follow the directions above for all of the modules at once.
Suragch
  • 484,302
  • 314
  • 1,365
  • 1,393
19

Close and reopen project as existing Android Studio project

Andrew Glukhoff
  • 898
  • 11
  • 9
10

After upgrading Android Studio, you can invalidate cache and restart.

File > Invalidate Caches / Restart…

introducir la descripción de la imagen aquí

Pang
  • 9,564
  • 146
  • 81
  • 122
Jorgesys
  • 124,308
  • 23
  • 334
  • 268
3

For some reason, those attributes are not found anymore in the 26 libraries. For increasing those libraries you have to also increase your compileSdk to 27. It is probable you will also have to download the sdk 27

Short version, following goes on the app `graddle``

android {
    compileSdkVersion 27
    //...
}

dependencies {
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support:design:27.1.0'
    //...
}

Long version, check all following files:

gradle-wrapper.properties

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

build.gradle (Project)

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.1.0'


        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

And finally build.gradle (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "cl.cutiko.testingupdate"
        minSdkVersion 21
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.android.support:design:27.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}
cutiko
  • 9,887
  • 3
  • 45
  • 59
2

Closing a project and then opening as existing one does wonders!

  • 1
    Aaaaand... this worked for me! Surprisingly. Though the code already compiles fine before, the red underline annoys me too much. Thanks man. – Aguragorn May 30 '18 at 04:46
2

Just importing project again did not work for me.

My solution was

  1. Delete .idea folder inside your project.
  2. Then close project by File> Close Project
  3. Then import project by File> New > Import Project OR from welcome Screen Import Project (Gradle, Eclipse ADT, etc.).

See screenshot for more info

1st solution

Or

2nd solution

Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
1

You can try to close the project and exit Android Studio (only closing and reimporting it didn't do it for me). Launch Android Studio and open the project again. That worked for me!

schv09
  • 995
  • 1
  • 9
  • 15
1

I closed and reopened project as existing Android Studio project (did not import it), and it worked! Thanks to Andrew Glukhoff 's comment.

Emmanuel R
  • 65
  • 4
0
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
implementation 'com.android.support:design:26.1.0'

update your dependencies with the above in build.gradle(project)

and put the below code in build.gradle(Module:app)

classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'io.realm:realm-gradle-plugin:3.7.1'
classpath 'com.google.gms:google-services:3.1.0'
geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
PRIYA
  • 419
  • 4
  • 2
0

For me the same symptom/error was caused by dragging and dropping a new image into 'drawable-xxhdpi' folder with a name Android Studio did not like - for example with a number or capital in the name.

No useful error message was given just the 'cannot resolve symbol R' message.

Even after synching the app and cleaning and rebuilding project, the issue remained that 'R' was not recognised with no other error indicated.

Closing and importing the project as suggested in other answers did not work, which makes sense given the root problem.

However, even though it appears this has not worked for others in the past, judging by other questions and answers on SO, deleting the new image from the drawable folder did work.

Similarly, and a better solution, obviously, renaming the image to remove any characters that Android does not like in resource names and then doing a clean and/or rebuild project also worked.

Mick
  • 24,231
  • 1
  • 54
  • 120
0

Problem #1

My problem was related with how I used an alpha/beta version of Android Plugin

File > Project Structure > Project

check your Android Plugin Version

I was using something called 3.3.0-beta, and yet in another project 3.1.0-alpha

changing it to 3.2.0 seems to clear up my issue, don't forget to change the one in build.gradle(Project) too

Problem #2

I had an error in one of my .xml files. I missed a @string resource. Please check all your xml files, and make sure they are all correct (opening an xml file should activate Android Studio linting, scroll through the file, it should complain in red if something is wrong)

Problem #3

In build.gradle I imported different versions of the android support libraries. e.g.

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:support-v4:27.1.0'

Please make sure they are the same version. And make sure that Android Studio doesn't complain anything inside your gradle dependencies. It might be that some of your dependencies also imported different android support library versions.

Steps to take after #1, #2 and #3

Clean your project Build > Clean Project

Invalidate cache and restart File > Invalidate Caches / Restart

After restart, wait for gradle build to finish, then voila!

grandia
  • 709
  • 7
  • 20
0

I updated my gradle version to 4.10.1 and did "fix and reimport". There were no libraries folder under .idea before. And then it worked

ozge s
  • 11
  • 2
0

Similar error for me when I update to com.android.tools.build:gradle 3.3.1 and gradle-4.10.1

I have tried the following method but didn't work:

  1. Clean Project - Rebuild Project
  2. Invalidate Caches / Restart
  3. Check .xml error (I didn't find any errors about xml )
  4. Modify .iml file

I fix this error by modify com.android.tools.build:gradle 3.2.1 and Restart my mac , I didn't know which one can fix it, but it really work for me .

Abominus
  • 13
  • 4
-2

How I solved it.:
how to solved

I updated Android studio to version 3.2, and two steps solved this problem.

  1. Deleted from Android studio welcome page.

  2. Open project again.

Worked for me.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Kellyoang
  • 64
  • 6
-4

Example

setContentView(R.layout.activity_login_ativity);

  1. Put the cursor in R
  2. Click Alt+Enter
  3. Choose import class R

Work for me :)

  • Would you please improve the explanation of your answer? Otherwise this post does not seem to provide a [quality answer](https://stackoverflow.com/help/how-to-answer) to the question. Please either edit your answer, or just post it as a comment to the question. – sɐunıɔןɐqɐp Aug 07 '18 at 09:26