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.

5
  • in 3.1.1 also we are getting this !
    – LOG_TAG
    Apr 11, 2018 at 7:53
  • in 3.1. 2 same issues below are not workings, what to do
    – giveJob
    Apr 29, 2018 at 18:51
  • @HemanthSP Closing and importing the project worked for me after updating Android Studio to 3.1.2.
    – JPM
    May 1, 2018 at 13:52
  • i tried 100 ways nothing working
    – giveJob
    May 3, 2018 at 5:21
  • 1
    try this: stackoverflow.com/a/50114143/2855059
    – M D P
    Jul 21, 2018 at 6:01

16 Answers 16

166

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

import project

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 Mar 28, 2018 at 15:05
  • 7
    Open an existing Android Studio project also works in Welcome to Android Studio. Mar 29, 2018 at 5:08
  • 3
    I closed and reopened project as existing Android Studio project (did not import it), and it worked! Mar 29, 2018 at 8:34
  • 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, 2018 at 14:10
  • 11
    WHY DOES THIS WORK?!
    – AndrewPK
    Apr 26, 2018 at 21:14
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.
1
  • 1
    This actually worked for me... Closing the project and re-importing didn't. Aug 6, 2018 at 17:54
19

Close and reopen project as existing Android Studio project

10

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

File > Invalidate Caches / Restart…

introducir la descripción de la imagen aquí

4
  • Thanks Jorgesys but this doesn't work for me either.
    – JPM
    Mar 28, 2018 at 13:30
  • 1
    For the first time ever - the simple solution actually worked ! Thanks.
    – AhabLives
    May 16, 2018 at 18:14
  • @AhabLives i hope in future versions of AS this problem will be solved but for now invalidate caché and restart is enough.
    – Jorgesys
    May 16, 2018 at 18:20
  • 1
    After trying several solutions, it works for me finally
    – Kislingk
    Sep 11, 2018 at 16:32
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'
}
3
  • Thanks cutiko, but unfortunately this doesn't help me as I was already using API 27 and your files look similar to mine.
    – JPM
    Mar 28, 2018 at 13:29
  • Ok so wild guess here, build/rebuild project? Also clean?
    – cutiko
    Mar 28, 2018 at 14:47
  • Thanks cutiko. I already tried that and it didn't help either.
    – JPM
    Mar 28, 2018 at 15:37
2

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

1
  • 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, 2018 at 4: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

0
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!

1

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

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'
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.

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!

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

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 .

-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.

0
-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 :)

1
  • 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. Aug 7, 2018 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.