appcompat-v7:21.0.0': No resource found that matches the given name: attr 'android:actionModeShareDrawable'

后端 未结 14 1901
不思量自难忘°
不思量自难忘° 2020-11-22 05:03

When attempting to use the latest appcompat-v7 support library in my project, I get the following error:

/Users/greg/dev/mobile/android_project/app/build/int         


        
相关标签:
14条回答
  • 2020-11-22 05:19

    I had added another project to my workspace and was trying to reference an activity from it in the manifest file, and I was getting this error. The problem is I was referencing the library incorrectly. This is how I fixed the problem:

    • Right click on project
    • Select Properties
    • Click on Android on left menu
    • Click on Add
    • Please select a Library Project

    The jar went into Android Dependencies folder and this error was fixed.

    0 讨论(0)
  • 2020-11-22 05:24

    While the answer of loeschg is absolutely correct I just wanna elaborate on it and give a solution for all IDE's (Eclipse, IntellJ and Android Studio) even if the errors differentiate slightly.


    Prerequirements

    Make sure that you've downloaded the latest extras as well as the Android 5.0 SDK via the SDK-Manager.

    Picture of the SDK Manager


    Android Studio

    Open the build.gradle file of your app-module and change your compileSdkVersion to 21. It's basically not necessary to change the targetSdkVersion SDK-Version to 21 but it's recommended since you should always target the latest android Build-Version.
    In the end you gradle-file will look like this:

    android {
        compileSdkVersion 21
        // ...
    
        defaultConfig {
            // ...
            targetSdkVersion 21
        }
    }
    

    Be sure to sync your project afterwards.

    Android Studio Gradle Sync reminder


    Eclipse

    When using the v7-appcompat in Eclipse you have to use it as a library project. It isn't enough to just copy the *.jar to your /libs folder. Please read this (click) step-by-step tutorial on developer.android.com in order to know how to import the project properly.

    As soon as the project is imported, you'll realize that some folders in the /resfolder are red-underlined because of errors such as the following:

    Errors in Eclipse

    error: Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material'.
    error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.*'
    error: Error: No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
    

    Solution

    The only thing you have to do is to open the project.properties file of the android-support-v7-appcompat and change the target from target=android-19 to target=android-21.
    Afterwards just do a Project --> Clean... so that the changes take effect.


    IntelliJ IDEA (not using Gradle)

    Similiar to Eclipse it's not enough to use only the android-support-v7-appcompat.jar; you have to import the appcompat as a module. Read more about it on this StackO-Post (click).
    (Note: If you're only using the .jar you'll get NoClassDefFoundErrors on Runtime)

    When you're trying to build the project you'll face issues in the res/values-v** folders. Your message window will say something like the following:

    Error:android-apt-compiler: [appcompat]  resource found that matches the given name: attr 'android:colorPrimary'.
    Error:(75, -1) android-apt-compiler: [appcompat] C:\[Your Path]\sdk\extras\android\support\v7\appcompat\res\values-v21\styles_base.xml:75: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
    // and so on
    

    Solution

    Right click on appcompat module --> Open Module Settings (F4) --> [Dependency Tab] Select Android API 21 Platform from the dropdown --> Apply

    Select API 21 Platform

    Then just rebuild the project (Build --> Rebuild Project) and you're good to go.

    0 讨论(0)
  • 2020-11-22 05:24

    I was up to date with everything and still got this error, not sure why but I think the image was corrupted in a strange way and after replacing the image I got rid of the error. Might be worth to try with a different image :)

    0 讨论(0)
  • 2020-11-22 05:26

    Make sure you clean your project in android studio (or eclipse),

    It should solve your issues

    0 讨论(0)
  • 2020-11-22 05:28

    I got the same error when I changed the Compile SDK version from API:21 to API:16. The problem was, appcompat version. If you need to use an older version of android API, so you have to change this appcompat version also. In my case (for API:16), I had to use appcompat-v7:19.+.

    So I replace dependencies in build.gradle as follows,

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:19.+'
    }
    

    And make sure you have older versions of appcompat versions on your SDK enter image description here

    0 讨论(0)
  • 2020-11-22 05:29

    I have encountered this issue with play-services:5.0.89. Upgrading to 6.1.11 solved problem.

    0 讨论(0)
提交回复
热议问题