Android Cannot resolve symbol '?attr/selectableItemBackground'

后端 未结 10 1834
北恋
北恋 2020-12-05 09:11


        
相关标签:
10条回答
  • 2020-12-05 09:34

    I have solved by,

    • Deleting the .idea folder in project explorer.
    • Invalidate Caches/Restart
    • Refresh Project Gradle
    0 讨论(0)
  • 2020-12-05 09:34

    This is what solved to me:

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

    1. Reimport the project

    0 讨论(0)
  • 2020-12-05 09:35

    For version Lollipop and higher use this:

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

    for Pre-Lollipop use this:

    android:foreground="?attr/selectableItemBackground"
    
    0 讨论(0)
  • 2020-12-05 09:39

    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

    0 讨论(0)
  • 2020-12-05 09:48

    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.
    0 讨论(0)
  • 2020-12-05 09:49

    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()
    
    0 讨论(0)
提交回复
热议问题