29
votes

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.

10
I have tried by several ways, but not fixed. I think the gradle version and Android studio version should be matched.James DCranmer

10 Answers

68
votes

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

20
votes

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.

8
votes

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.

6
votes

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

enter image description here

3
votes

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
votes

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.

1
votes

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

0
votes

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

0
votes

Simplest Solution

  • Close project
  • Import/Reopen project again (Open from directory)
-2
votes

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