29

As stated in style.xml, there is a weird error, which shows Cannot resolve symbol 'Theme', which is quite strange.

See pic of the error :- enter image description here

My Project Specs:-

Using Android Studio 3.0

and gradle version 3.0.0

and distributionUrl=https://services.gradle.org/distributions/gradle-4.1-all.zip

Edit:-

Tried clearing the cache by going to File > Invalidate Cache/Restart > Invalidate and Restart, but to no avail, as the error persists.

WindRider
  • 11,958
  • 6
  • 50
  • 57
Pulkit
  • 1,020
  • 3
  • 12
  • 26

10 Answers10

68

Had the same issue after upgrading to Android Studio 3.1 (EDIT: bug still present at v3.1.3). What worked for me was clicking File > Close Project and then reopening the project from Studio's dialog.

Android Studio's Entry Screen

  • 4
    The is was the only thing that worked for me too, and i tried the other answers too (bug in 3.1 i believe). – Mihai Mar 31 '18 at 13:31
  • Spent an hour doing all sorts of other weird stuff to try fixing this after 3.1, thank you! – Deem Apr 01 '18 at 02:58
  • Finally something that worked! (v3.1) - Must be a widely known bug? – MHopstad Apr 03 '18 at 08:54
  • Works for me too. Thanks – Carlos Eduardo Apr 14 '18 at 21:14
  • Worked for me after removing it from recent projects. (File, Open Recent, manage projects) – SammyT Apr 15 '18 at 00:10
  • 1
    After all different kind of tries AS 3.1.1 still, continue with the above bug. – blackjack Apr 17 '18 at 05:21
  • Similar approach but using "Import project (Gradle, Eclipse..)" did the trick for me. This seems to force all .idea files to be recreated from scratch. – devconsole Apr 18 '18 at 09:47
  • This is zany -- the second Q&A I've consulted for this problem (studio v3.1.2), tried cleaning and rebuilding, syncing, disabling build cache, closing and reopening (*but from the sidebar list*), fiddling with gradle and appcompat versions and going through all of the above again -- to no avail. Then this worked. >_> – CodeClown42 Apr 26 '18 at 12:45
  • 1
    It worked for me (Android 3.1.2). Neither Invalidate cache/restart nor Sync Project with Gradle files worked. It was sufficient to close the project and reopen it as described here. Now the error is gone. –  May 02 '18 at 12:06
  • It worked for me too (Android 3.1.2). Just like pierluca's answer, neither "Invalidate cache and restart", nor "Sync gradle" worked – SnuKies May 04 '18 at 13:43
  • This "Hello, IT. Have you tried closing it and opening again?"-solution saved my day. Thanks bro. – cassioso May 11 '18 at 12:51
  • Thank you @cassioso for making me laugh so hard when I got the joke. Edited answer afterwards, to indicate that the bug (?) is still present at v3.2.1 – Ευάγγελος Μπίλης May 11 '18 at 15:31
20

Another possible reason is: Google's maven repository is not set for the build script.

Open your project's main build.gradle add this line:

buildscript {
    repositories {
        google()  <-- this
        // Be also sure that google() is before jcenter()
    }
}

Without this, it may not be able to download the Android Studio Gradle plugin 3.0+. It's not distributed in jCenter but in the Google's maven repository.

WindRider
  • 11,958
  • 6
  • 50
  • 57
  • Vote up, it's the only correct solution, at least in my case. This is weird, since it affects xml editor only, it compiles fine even without `google()` repository added. – user1209216 Nov 23 '17 at 08:29
  • 2
    Neither this, nor the other suggestions worked for me with plugin 3.1.x but fortunately I can still compile the project (despite the red letters that indicate an error). – Gabor Feb 01 '18 at 21:52
  • Even running lint works fine despite the red letters. Must be an IDE bug. – Gabor Feb 01 '18 at 22:00
  • @Gabor, the IDE problem is different and it's something newer. I've started seeing it after an upgrade few weeks ago. But the error from the OP is a real blocker. You can't build unless you fix it. – WindRider Feb 02 '18 at 10:35
  • 2
    This doesnt help – Lakshman Chilukuri Mar 02 '18 at 04:57
  • Try this if above answer is not working : https://stackoverflow.com/a/43255281/3674079 – quangkid Mar 22 '18 at 01:48
  • 2
    Solution does not work for me. The Google Maven repo is already in my gradle.build file. – jrswgtr Apr 11 '18 at 11:15
8

What worked for me was to click on Gradle to open the Gradle projects tool window and than on refresh. I think some depedencies where not loaded correctly.

Jelmer Brands
  • 192
  • 2
  • 9
6

In my case, Invalidate Caches/Restart worked fine for me.

enter image description here

jagapathi
  • 1,635
  • 1
  • 19
  • 32
3

Goto File -> Invalidate Caches / Restart... -> Invalidate and Restart

Android Studio will sort-of close and delete all caches, indexes, etc.. Then, Android Studio will open again. Indexing will be done and you're ready to proceed.

2

It seems to be a setting update of "injected references". Search this word in settings dialog and change its "Severity" option to a different value and apply, then change back to its original choice. The error highlight in the editor then disappears.

albert
  • 364
  • 3
  • 8
  • Thank you, can you explain what is "injected references"? BTW updated to beta 5 and issue got resolved :) – Pulkit Sep 11 '17 at 14:36
  • I was not quite sure and just met the same problem as you. I clicked the bulb icon by moving cursor to the error highlight and it gave some hints about the problem. – albert Sep 16 '17 at 04:51
  • 1
    Click on File -> Invalidate and Restart -> Invalidate and Restart to fix the problem – Pulkit Sep 16 '17 at 05:04
1

Solution 1:

  1. GOTO > 'build.gradle(Module:app)',
  2. ADD > "buildToolsVersion '28.0.2'" as following :

android {
    signingConfigs {}
    compileSdkVersion 28
    defaultConfig
    {
        applicationId "com.example.project"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes
    {
        release
        {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    buildToolsVersion '28.0.1'
}
  1. Click on 'Sync Now', and it's done.
  2. GOTO > 'File' > 'Invalidate Cache/Restart'.
  3. Done.

If That doesn't work, following might help (Solution 2) :

  1. GOTO > 'SDK Manager' > 'SDK Tools' > Click on 'Show Package Details',
  2. Check if there is a NEW Version of 'SDK Build-Tools' Available,
  3. Then Download it and Change to newer version "buildToolsVersion '28.0.x'" in 'build.gradle (Module:app)',
  4. Sync again.
  5. GOTO > 'File' > 'Invalidate Cache/Restart'.
  6. Done.

If That doesn't work, following might help (Solution 3) :

  1. Remove/Cut following dependencies :

    implementation 'com.android.support:appcompat-v7:x.x.x'
    implementation 'com.android.support:design:x.x.x'
    
  2. Click on 'Sync Now',

  3. Add/Paste dependencies again and Sync again.
  4. Done.

NOTE : You can do Solution 1 then 2 then 3 for better results.

Hope it helped :)

Keyur Sureliya
  • 164
  • 3
  • 11
0

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

Hardip
  • 360
  • 3
  • 9
0

Simplest Solution

  • Close project
  • Import/Reopen project again (Open from directory)
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
-2

Delete 'com.android.support:appcompat-v7:27.0.0','com.android.support:design:27.0.0' compile from app build.gradle then sync and then again paste those 2 compile then sync.... it will solve

Prodip Roy
  • 11
  • 3