182

Screenshot

Since today, Android Studio can't find the AppCompat themes in styles.xml, but for example AppCompatActivity in code does get recognized. My Android Studio version is 2.2.2, Build #AI-145.3360264

I already tried upgrading to the latest build tools, compile sdk (25) version etc. but it didn't fix the problem.

At the moment I have installed the following (from sdk manager):

  • android api: 19 and 23
  • sdk platform tools: 25.0.1
  • sdk tools: 25.2.3
  • build-tools: 23.0.2 and 25.0.1
  • support repository: 40
  • google repository: 39

and a few others, that shouldn't be necessary to list here.

build.gradle of app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.1'
    defaultConfig {
        applicationId "xxx.xxxxxxxx.xxxxxxxxx" //not the real applicationId
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {

        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile files('libs/RootTools.jar')
    compile 'com.android.support:support-v4:23.+'
    compile 'com.android.support:support-v13:23.+'
    compile 'com.android.support:appcompat-v7:23.+'
    compile 'com.android.support:design:23.+'
    compile 'com.android.support:cardview-v7:23.+'
    compile 'com.android.support.constraint:constraint-layout:1.0.0-beta4'
    compile 'de.hdodenhof:circleimageview:2.1.0'
}
FLP
  • 2,050
  • 2
  • 14
  • 16
  • 4
    Does the project compile or is only the IDE complaining? Invalidate caches/restart. – Eugen Pechanec Nov 26 '16 at 20:24
  • 1
    Invalidate caches/restart didn't change anything, only the IDE is complaining about it and compiling works fine. Sorry for possibly wasting your time with this, I was only concerned to make the error go away and didn't think that compiling still works normally ^^ – FLP Nov 26 '16 at 21:25
  • 1
    Im having the same error, but compiles ok – Pablo Cegarra Dec 01 '16 at 09:03
  • 10
    https://stackoverflow.com/a/48734990/8311441 When Every other solution failed This helped me – Tabish Apr 06 '18 at 05:37
  • 1
    Just came across this issue (in Android studio 3.1.3). The remove `appcompat-v7` and sync before adding it again helped. Let's all upvote and hope for updates here issuetracker.google.com/issues/67790757 – sunadorer Jul 03 '18 at 11:54

24 Answers24

217

Another solution that worked for me with Android Studio 3.1.2:

delete these from build.gradle if you have them:

'com.android.support:appcompat-v7:27.1.1' 'com.android.support:design:27.1.1'

then sync, then undo delete, then sync again.

M D P
  • 4,525
  • 2
  • 23
  • 35
107

I encountered this after updating to Android Studio 3.1.

None of the other answers listed here worked for me, however when I switched my appcompat support lib version to the latest 28.0.0-alpha1 then back to 27.1.0 that it was on before, it worked.

Seems the new version of Android Studio lost connection to where the library was synced to and just needed to have it reset.

kassim
  • 3,880
  • 3
  • 26
  • 27
  • Thanks for this. Like you, none of the other answers worked for me after upgrading to AS 3.1, but this did the trick. You just have to be sure to sync after each change. – Ted Hopp Apr 04 '18 at 16:52
  • 7
    I was on 26.0.1 and updating to 27.1.1 (and compile version to from 26 to 27) made all the errors go away (literally nothing else would) – Daniel Wilson Apr 06 '18 at 16:12
  • I also was having this problem after updating to AS 3.1. Thanks this helped me. – Bek Apr 10 '18 at 11:25
  • 4
    Going back to 26.0.1 and then to 27.1.1 works as well – adek111 Apr 10 '18 at 17:15
  • 8
    It is not a good thing that this is the solution that works most reliably in my experience. AS shouldn't require these kinds of hacky solutions. – jwehrle Apr 17 '18 at 17:39
  • 1
    This solution worked. I'm just disappointed that silly IDE + Gradle troubleshooting takes up a lot of time. – Rohan Apr 25 '18 at 17:09
  • Bugs like this makes me go crazy sometimes with android development. Really, nothing else helps, even using the nuke "Invalidate caches and restart" option, nothing helps but putting the thing back to 26.x.x, doing a full sync, then back to 27.1.1. and doing a sync again. Crazy. – ZoltanF May 07 '18 at 10:59
  • I'm having to do this with several libraries, not just support. Such an upsetting experience. – kassim May 08 '18 at 17:10
  • This works like Magic. Android studio sometimes really suck. – Srujan Barai May 31 '18 at 21:14
96

No need to change anything.

Just press small button on top "Sync Project with Gradle Files"

Vadim
  • 3,855
  • 2
  • 17
  • 22
91

EDIT: As @Alexey noted, bug still appears in Android Studio v3.1.4

This worked for me:

  • Click File > Close Project
  • Reopen the project from Studio's dialog.

enter image description here

  • 3
    Note that this will also reset your window preferences - the sizes of the various panes, what tabs are shown at start, etc. It will also change what build variant you are on back to debug. This will effectively wipe all editor preferences and settings for the project. – InsanityOnABun May 16 '18 at 10:40
  • This worked! But also curious to know, why this happened in the first place. I have modified few colors in my colors.xml. Failed to understand how is that related or may be AS 3.1.2 bug? – Rohit Sharma Jun 12 '18 at 07:21
  • AndroidStudio bug. As [@InsanityOnABun](https://stackoverflow.com/users/929560/insanityonabun) mentioned, closing and opening the project in such a manner, resets many things. In the process, the bug related problem dissapears. – Ευάγγελος Μπίλης Jun 12 '18 at 07:38
  • 1
    @ΕυάγγελοςΜπίλης just encountered this bug in Android Studio 3.1.3 and resolved it your way; you may update your answer that everyone knows it works for AS 3.1.3 also. – Atif Farrukh Jun 21 '18 at 10:04
  • None of the other answers worked but this did! Wonderful.. Works on **AS 3.1.3** perfectly. Weirdly started getting this bug only after modifying something in styles, although I rolled it back.. – sanjeev Aug 06 '18 at 17:30
  • I dont know how this is working. But it really works. should be the accepted answer! Google should fix this issue. – Ron Daulagupu Aug 12 '18 at 17:31
  • This solved it for me. This is still a problem in 2022.. – automaton Mar 08 '22 at 15:32
38

That's because of feature called "build cache" that is enabled by default in build Android Plugin since 2.3.0. It creates files in build cache outside of project folder (in my case -- in \Users\%username%\.android\build-cache) Theese files are intended to be common between your projects.

And then Android Studio is unable to navigate in theese files. That's all.

If you want to disable Build Cache, add android.enableBuildCache=false to gradle.properties file. Then restart Android Studio.

more info here: https://developer.android.com/studio/build/build-cache.html#disable_build_cache

babay
  • 4,689
  • 1
  • 26
  • 40
27

I have had the same problem. The only solution that worked for me was to manually delete the support libraries in file system and sync the project to let Android Studio download them again.

Steps:

  1. Go to your project folder in File system
  2. Go to .idea\libraries
  3. Delete all the Gradle__com_android_support_****.xml files
  4. Open Android Studio
  5. Select File > Sync with File System
  6. Once that is done, Select File > Sync Project with Gradle Files
  7. Build Project

And now your error should be gone!!!

Tricky Bay
  • 796
  • 9
  • 20
  • Only in this way worked for 28 build tool version. :) – Farya Sep 28 '18 at 10:10
  • Works like a charm! Thanks! – Hexise Nov 07 '18 at 06:47
  • @Tricky Bay Do you have solution for this problem? Thanks!https://stackoverflow.com/questions/53323910/android-resource-linking-failed-textappearance-compat-notification-on-android?noredirect=1#comment93599900_53323910 – Eric Nov 18 '18 at 16:48
19

you can hit file -> invalidate Caches / Restart ... if it doesn't fix the issue you can close the project (file-> close project) and import it (file -> new -> import project.

Marco T
  • 191
  • 1
  • 5
  • In my case, `Invalidate Caches / Restart ...` worked. It seems the reason of this error is various. – wonsuc May 28 '18 at 10:51
  • 1
    This worked for me. close project + remove project (with the x on the right top) + import existing project Android Studio 3.1.3 com.android.tools.build:gradle:3.1.3 – Jan Jul 08 '18 at 07:07
  • Ya worked in 2018! android studio 3.1.3 gradle 3.1.3 – PanCrucian Jul 16 '18 at 13:33
12

I switched support lib to version 27.1.1 and problem has been solved. Seems like some bug in 27.1.0

  • 2
    I agree, dont use 27.1.0 if you have a viewpager. My app was getting 20 crashes a day. https://issuetracker.google.com/issues/74130311 Fixed in 27.1.1 and my app seems to load faster due to the setUserVisibleHint loading the visible fragment first. – SammyT Apr 14 '18 at 10:46
  • 6
    @SammyT - I don't think this particular issue has to do with 27.1.0 vs 27.1.1, since I just had the same problem with 27.1.1. I think it's just changing support lib versions that cleans up the error, regardless of the particular version(s) used. See [the answer by @kassim](https://stackoverflow.com/a/49638518/535871). – Ted Hopp Apr 29 '18 at 07:58
  • 1
    @TedHopp I agree with you. For this particular issue, closing the project and removing the projects from recent projects, then re-opening the project fixes it for me (regardless of the support library version). Sorry my comment reads wrong to how I intended, I was just adding be careful of using 27.1.0 if you have a viewpager, as there is a bug in that version of the library. – SammyT May 01 '18 at 12:44
  • Thanks, this worked for me after lot of try. I used compile sdk 27 and upgraded each to 27.1.1 – sanjeeb Aug 28 '18 at 10:50
  • No, its not, I use the 27.1.1, and the problem persist for me. – Eli Sep 07 '18 at 09:08
10

I went through the same problem when I upgraded to alpha-2.

I looked at this link: http://tools.android.com/recent, but the only thing that worked well was:

Change this: Classpath 'com.android.tools.build:gradle:2.3.0-alpha2'

For this: Classpath 'com.android.tools.build:gradle:2.2.3'

In your build.gradle (Project)

Duan Bressan
  • 627
  • 6
  • 13
4

Only this worked for me

  • Close project (File> Close Project)
  • Import / Re-Open project again (NOT from Recent)

Error should be resolved now.

If that fails, try below-

  • Open build.gradle, remove appcompact-v7 dependency and sync project.
  • Add appcompact-v7 dependency and sync.
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
3

I encountered same problem like this.Just the difference is I was using Studio 2.2.3. This is what solved my problem:

In my project level gradle I had:

classpath 'com.android.tools.build:gradle:2.3.0-alpha2' (which was a result of updating studio)

which I replaced with: classpath 'com.android.tools.build:gradle:2.2.3'

I think you should look for a compatible classpath for your gradle configuration.

2

I was having the same issue after linking Firebase to my app. Updating the build.gradle in the app module did the trick, updated to:

implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-database:11.8.0'
1

I had also the same problem when I upgraded my android studio from 2.2.2 to 2.3 Canary Version. Although the new beta version of 2.3 is released yet it is using the gradle plugin of 2.2.3 which is of stable version.

So just change the classpath dependency in buildscript of build.gradle project level from alpha to 2.2.3 and sync it. It'll resolve the issue or change to the more appropriate version with respect to your channel version.

More on gradle watch this Gradle Recipes for android Ken Kousen - Gradle Summit 2016

https://www.youtube.com/watch?v=4L6wHTVmxGA

Karthik Saxena
  • 768
  • 3
  • 9
  • 25
1

In newer versions of Android Studio, we are asked to use 'AppCompat'. Some users uncheck that and still use the Theme.AppCompat. That makes up this error. Same happened with me.

Solution is to add this line in your build.gradle (app).

compile 'com.android.support:appcompat-v7:26.1.0'
TheOnlyAnil
  • 877
  • 1
  • 15
  • 27
1

@Daniel Wilson made a comment in one of the answers that solved this issue for me. I wanted to add add as an answer to draw more attention to this solution.

Updating compileSdkVersion and targetSdkVersion from 26 to 27 (and then of course updating the dependencies) eliminated the errors for me.

seekingStillness
  • 4,833
  • 5
  • 38
  • 68
1

Mine was fixed by deleting the .gradle file from the folder and re-importing the project in Android Studio

Ioannis I
  • 298
  • 3
  • 15
1

I also faced the problem with Android Studio 3.1 , syncing does not help me.

Then I switched back to

`'com.android.support:design:27.1.0'` from : `'com.android.support:design:27.1.1'`

and added android.enableBuildCache=false to gradle.properties to disable build cache

1

This is weird, I encounter this problem as below:

  • Android Studio is 3.1.2
  • support lib version is 27.0.0

I solve this by below:

  1. change support lib version to 27.1.0, and "Sync Project with Gradle Files", then this error disappear
  2. change support lib version to 27.0.0,and "Sync Project with Gradle Files", then this error not appear again
zhangliang
  • 1,041
  • 9
  • 9
1

Deleted .idea and .gradle from project folder. Then sync with gradle files, it worked.

n1m1
  • 869
  • 1
  • 9
  • 20
1

My solution (which has just worked in Android Studio 2022.1.1) is to comment out this (or similar) line in the build.gradle file of the app module:

implementation 'com.google.android.material:material:1.8.0'

Then syncing this file with Gradle ("Sync Now"), then uncommenting the line and syncing again.

Rado
  • 133
  • 2
  • 7
0

I changed my gradle version from

classpath 'com.android.tools.build:gradle:2.3.0'

to

classpath 'com.android.tools.build:gradle:2.2.3'

and it works now!

Pang
  • 9,564
  • 146
  • 81
  • 122
0

I ran into the same problem when updating the Android Studio software. What I did was this:

Go to the Gradle Settings as follows (this path is for Mac, but should be similar on Windows):

Android Studio -> Preferences -> Build, Execution, Deployment -> Gradle.

Then pick "Use default gradle wrapper (recommended)".

If you already have that option chosen then your problem must lie somewhere else.

REG1
  • 486
  • 4
  • 15
0

In Android Studio 3.1.3, the simple work around:

"Sync Project with Gradle Files"

Waqar UlHaq
  • 6,144
  • 2
  • 34
  • 42
0

If none of these methods mentioned by other contributors does not work for you..

Then please simply ignore this...

Even flutter officials also said to ignore these errors..

Caution*** Only ignore after trying all the methods.If above methods solve your errors then fine otherwise you can ignore these..

This type of errors happen after installing latest version of flutter sdk,gradle ,android studio and other plugins -packages

If you are using latest version then you have to ignore these errors.

raman raman
  • 1,655
  • 4
  • 22
  • 34