Android Cannot resolve symbol '?attr/selectableItemBackground'

AndroidAndroid Xml

Android Problem Overview


<android.support.v7.widget.CardView
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="@dimen/card_outer_padding"
    android:layout_marginTop="@dimen/card_outer_padding"
    android:layout_marginRight="@dimen/card_outer_padding"
    android:layout_marginBottom='@{model.cardBottomMargin}'
    android:foreground="?attr/selectableItemBackground"
    android:onClick="@{model::onCardClick}"
    app:cardElevation="2dp"
    app:cardCornerRadius="2dp"
    app:cardUseCompatPadding="true">
</android.support.v7.widget.CardView>

I got this error message

Cannot resolve symbol ?attr/selectableItemBackground Validates resource references inside Android XML files.

<TextView
    android:id="@+id/country_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="40dp"
    android:text="@{model.name}"
    style="@style/TextAppearance.AppCompat.Headline"
    tools:text="Country"/>

And, I got a similar error for the above as well

Cannot resolve symbol '@style/TextAppearance.AppCompat.Headline'
Validates resource references inside Android XML files.

Any pointer would be great! Thank you! It seems to be related to this thread but no solution was provided:

Android Solutions


Solution 1 - Android

I believe this is a communication problem with the IDE and Android Gradle Plugin. In any case, the only way I've reliably found to resolve this is to delete the problematic libs in the .idea/libraries/ folder.

So, for you, since the lint checks aren't recognizing ?attr/selectableItemBackground

  1. LOCATE the Gradle__com_android_support_xxx.xml files
  2. DELETE those files
  3. SYNC IDE with file system
  4. SYNC project with Gradle files
  5. REBUILD your project

You can sync by clicking on 'File' at the top by the toolbar and selecting "Sync with File System" and then afterwards selecting "Sync project with gradle files".

I've tried other suggested solutions - had the appcompat-v7 dependency in my module build.gradle file & the google() repository as the first line in the project build.gradle dependencies. Nada.

These solutions also haven't helped...

  • Invalidating the caches/restarting didn't work.
  • Cleaning/Rebuilding the project.

Solution 2 - Android

For version Lollipop and higher use this:

android:foreground="?android:attr/selectableItemBackground"

for Pre-Lollipop use this:

android:foreground="?attr/selectableItemBackground"

Solution 3 - Android

2 options:

Option 1

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

Option 2

Run this command in root of project and resync project

##Linux:

rm .idea/libraries/Gradle__com_android_support_*.xml

##Windows:

del .idea\libraries\Gradle__com_android_support_*.xml

Solution 4 - Android

I faced with same error after updating Kotlin. Solved with "Invalidate caches/Restart"


UPDATE Today this solution did not helped me. But the solution of this question did: Android Studio 3.1 Cannot Resolve Symbol (Themes, Widget, attr, etc.)

Solution 5 - Android

Both resources are defined with the Android Support Library and since these symbols cannot be resolved, it seems like you're missing to define the support dependency.

dependencies {
    compile "com.android.support:appcompat-v7:$androidSupportVersion"
}

Solution 6 - Android

I have solved by,

  • Deleting the .idea folder in project explorer.
  • Invalidate Caches/Restart
  • Refresh Project Gradle

Solution 7 - Android

In my case help adding maven to build.gradle Project in buildscripts.repositories AND allprojects.repositories. It looks like this:

google()
maven { url 'https://maven.google.com' }
jcenter()

Solution 8 - Android

This is what solved to me:

  1. Close Android Studio
  2. Delete .idea directory in the root project directory

enter image description here

  1. Reimport the project

enter image description here

Solution 9 - Android

I updated my gradle version to 4.10.1 and fix and reimport repaired it. There were no libraries folder under .idea before.

Solution 10 - Android

If you use applicationContext for LayoutInflater, then replace it to normal context. It works for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJun711View Question on Stackoverflow
Solution 1 - AndroidwooldridgetmView Answer on Stackoverflow
Solution 2 - AndroidVishal YadavView Answer on Stackoverflow
Solution 3 - AndroidHerberthObregonView Answer on Stackoverflow
Solution 4 - AndroidZakir ShikhliView Answer on Stackoverflow
Solution 5 - AndroidtynnView Answer on Stackoverflow
Solution 6 - AndroidNazeer AhamedView Answer on Stackoverflow
Solution 7 - AndroidSerjantArbuzView Answer on Stackoverflow
Solution 8 - AndroidDragonTView Answer on Stackoverflow
Solution 9 - Androidozge sView Answer on Stackoverflow
Solution 10 - AndroidzsxeeeView Answer on Stackoverflow