Android Studio 3.1 Cannot Resolve Symbol (Themes, Widget, attr, etc.)

27,169

Solution 1

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

import project

Solution 2

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.

Solution 3

Close and reopen project as existing Android Studio project

Solution 4

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

File > Invalidate Caches / Restart…

introducir la descripción de la imagen aquí

Solution 5

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'
}
Share:
27,169
JPM
Author by

JPM

I'm trying to learn as much as I can, and I thought this site would be a great resource to help with that. Thanks to everyone who has given me advice so far, it really is appreciated.

Updated on July 05, 2022

Comments

  • JPM
    JPM almost 2 years

    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
    JPM about 6 years
    Thanks cutiko, but unfortunately this doesn't help me as I was already using API 27 and your files look similar to mine.
  • JPM
    JPM about 6 years
    Thanks Jorgesys but this doesn't work for me either.
  • cutiko
    cutiko about 6 years
    Ok so wild guess here, build/rebuild project? Also clean?
  • BenjaminButton
    BenjaminButton about 6 years
    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
  • JPM
    JPM about 6 years
    Thanks cutiko. I already tried that and it didn't help either.
  • Andy Sander
    Andy Sander about 6 years
    Open an existing Android Studio project also works in Welcome to Android Studio.
  • Andrew Glukhoff
    Andrew Glukhoff about 6 years
    I closed and reopened project as existing Android Studio project (did not import it), and it worked!
  • N Dorigatti
    N Dorigatti about 6 years
    For those of you that don't want to reimport a project, the solution that worked for me is here: stackoverflow.com/questions/49520097/…
  • JPM
    JPM about 6 years
    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.
  • Sai
    Sai about 6 years
    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?
  • Zuhaib Ahmad
    Zuhaib Ahmad about 6 years
    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.
  • AndrewPK
    AndrewPK about 6 years
    WHY DOES THIS WORK?!
  • AhabLives
    AhabLives almost 6 years
    For the first time ever - the simple solution actually worked ! Thanks.
  • Jorgesys
    Jorgesys almost 6 years
    @AhabLives i hope in future versions of AS this problem will be solved but for now invalidate caché and restart is enough.
  • Aguragorn
    Aguragorn almost 6 years
    Aaaaand... this worked for me! Surprisingly. Though the code already compiles fine before, the red underline annoys me too much. Thanks man.
  • RushDroid
    RushDroid almost 6 years
    Wooowww i don't know why its worked but thank you so much.
  • Saman Sattari
    Saman Sattari almost 6 years
    Note that u must open it not from Recent projects but from choosing the location of project
  • Hugo Allexis Cardona
    Hugo Allexis Cardona over 5 years
    This actually worked for me... Closing the project and re-importing didn't.
  • sɐunıɔןɐqɐp
    sɐunıɔןɐqɐp over 5 years
    Would you please improve the explanation of your answer? Otherwise this post does not seem to provide a quality answer to the question. Please either edit your answer, or just post it as a comment to the question.
  • Kislingk
    Kislingk over 5 years
    After trying several solutions, it works for me finally
  • not2qubit
    not2qubit about 5 years
    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.)