23

I updated my android studio to latest version - 3.0.1. Since then it complains 'Cannot resolve symbol' for Theme and ThemeOverlay in the following lines of code. App runs fine but they are marked in RED in the file.

styles.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"></style>
 <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

build.gradle is updated with the latest version

 dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
    }
Zoe
  • 27,060
  • 21
  • 118
  • 148
BRDroid
  • 3,920
  • 8
  • 65
  • 143
  • 3
    you need to check this :- https://stackoverflow.com/questions/40822173/cannot-resolve-symbol-theme-in-styles-xml-android-studio – InsaneCat Dec 09 '17 at 07:22
  • 3
    I am also, facing the same issue in 3.0. However, the app just work fine. – Saran Sankaran Dec 09 '17 at 07:38
  • You can raise issue https://developers.google.com/issue-tracker/guides/create-issue-ui . May be REASON behind this. – IntelliJ Amiya Dec 09 '17 at 07:38
  • any solution i face same issue – Vishal Thakkar Jun 16 '18 at 12:02
  • Similar problem here (AS 3.1.3): in the manifest, this line has an error (in red): `android:theme="@style/AppTheme.ActionBar">`, and in styles.xml, the words `Theme` and `ThemeOverlay` are in red, with an error message `AppTheme.ActionBar` is not found. – Robert Lewis Jun 22 '18 at 16:39
  • @RobertLewis Have you tried the solution below by "Nick Karamoff" it sounds strange - but has worked for me too (AS 3.1.3) – sunadorer Jul 03 '18 at 11:57

7 Answers7

29

1)Close the project from the File menu.

2)Open the project again as existing Android Studio project.

enter image description here

This fix my problem.

V.March
  • 1,820
  • 1
  • 21
  • 30
  • Wow.. Thts indeed a trick...I too got my problem resolved.... But how does this differs from syncing gradle is still doubtful... ! Thanks @V.March – Sreehari Jul 23 '18 at 10:56
15
  1. In the app/build.gradle remove the line responsible for the appcompat package (something like implementation 'com.android.support:appcompat-v7:27.1.1')
  2. Perform the Gradle sync. It will break and show a lot of errors
  3. Bring the original line back
  4. Perform the Gradle sync once again

This will magically solve the problem that for no reason appeared in the 3.0.1

Nikita Karamov
  • 517
  • 1
  • 5
  • 18
  • 1
    This should be the accepted answer. Strange magic work-around but really helps. Thanks Nick! I've upvoted and commented on https://issuetracker.google.com/issues/67790757 and hope this will be fixed soon. – sunadorer Jul 03 '18 at 11:48
  • This also worked for me. It didn't initially because other dependencies were bringing in appcompat library, so I added exclude to all Android dependencies "{ exclude module: 'appcompat-v7' }" then it worked. – TrueCoke Sep 16 '18 at 08:18
4

Something got messed up on the indexing of the Project when you updated the version.

To fix go to the menu:

File -> Invalidate Caches/Restart

that will reopen and re-index the whole project, the error should be gone.

Carlos B. Flores
  • 2,611
  • 19
  • 10
2

Found Easiest Way

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

The error should be gone.

If(that_did_not_work)

  • Open build.gradle, remove appcompact-v7 dependency and sync.
  • Again add that dependency and sync.

Error Gone!

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

I had this same error so i compared it to gradle file of another project which wasn't showing error. In your build.gradle(Module:app) under dependencies, add the following line:

implementation 'com.android.support:preference-v7:28.0.0'
Tayyab Mazhar
  • 1,560
  • 10
  • 26
0

Invalidate Caches / Restart from file menu solved it for me. Didn't see the same answer below

zulu_papa
  • 415
  • 6
  • 12
0

In my case , I have already defined the value in styles.xml file but it still notice me the problem like this:

the value has been defined

But I still got an error like below:

enter image description here

I solve this problem by change the value like below:

enter image description here

Hope this is work for you too.Thank you!

Community
  • 1
  • 1
linjiejun
  • 1,468
  • 15
  • 22