appcompat-v7:21.0.0':找不到与给定名称匹配的资源:attr 'android:actionModeShareDrawable'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26431676/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:24:02  来源:igfitidea点击:

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

androidgradlexamarin.androidandroid-support-libraryandroid-5.0-lollipop

提问by loeschg

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

尝试在我的项目中使用最新的 appcompat-v7 支持库时,出现以下错误:

/Users/greg/dev/mobile/android_project/app/build/intermediates/exploded-aar/com.android.support/appcompat-v7/21.0.0/res/values-v11/values.xml
Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(36, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.

How do I fix this?

我该如何解决?

回答by reVerse

While the answer of loeschgis 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.

虽然loeschg的答案绝对正确,但我只想详细说明它并为所有 IDE(Eclipse、IntellJ 和 Android Studio)提供解决方案,即使错误略有不同。



Prerequirements

先决条件

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

确保您已经下载了最新的extras以及Android 5.0 SDK通过 SDK-Manager 下载的。

Picture of the SDK Manager

SDK 管理器图片



Android Studio

安卓工作室

Open the build.gradlefile of your app-module and change your compileSdkVersionto 21. It's basically not necessary to change the targetSdkVersionSDK-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:

打开build.gradle你的 app-module 文件并将你的更改compileSdkVersion为 21。基本上没有必要将targetSdkVersionSDK-Version更改为 21,但建议您始终以最新的 android Build-Version 为目标
最后,您的 gradle-file 将如下所示:

android {
    compileSdkVersion 21
    // ...

    defaultConfig {
        // ...
        targetSdkVersion 21
    }
}

Be sure to sync your project afterwards.

请务必在之后同步您的项目。

Android Studio Gradle Sync reminder

Android Studio Gradle 同步提醒



Eclipse

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

当使用v7-appcompat在Eclipse中,你必须把它作为一个库项目。仅将 *.jar 复制到您的/libs文件夹是不够的。请阅读这(点击)一步一步的教程developer.android.com才能知道如何正确导入项目。

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:

导入项目后,您会发现文件夹中的某些文件/res夹由于以下错误而带有红色下划线:

Errors in Eclipse

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.propertiesfile of the android-support-v7-appcompatand change the target from target=android-19to target=android-21.
Afterwards just do a Project --> Clean...so that the changes take effect.

您唯一需要做的就是打开 的project.properties文件android-support-v7-appcompat并将目标从 更改target=android-19target=android-21
之后只需执行 aProject --> Clean...以使更改生效。



IntelliJ IDEA (not using Gradle)

IntelliJ IDEA(不使用 Gradle)

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

与 Eclipse 类似,仅使用android-support-v7-appcompat.jar; 是不够的。您必须将其appcompat作为模块导入。在此StackO-Post上阅读更多相关信息(点击)
注意:如果你只使用.jar你会得到NoClassDefFoundErrors运行时

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:

当您尝试构建项目时,您会遇到res/values-v**文件夹中的问题。您的消息窗口将显示如下内容:

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 appcompatmodule --> Open Module Settings (F4) --> [Dependency Tab]Select Android API 21 Platform from the dropdown --> Apply

右键单击appcompat模块 --> 打开模块设置 (F4) --> [依赖项选项卡]从下拉列表中选择 Android API 21 平台 --> 应用

Select API 21 Platform

选择 API 21 平台

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

然后只需重建项目 (Build --> Rebuild Project) 就可以了。

回答by loeschg

This is likely because you haven't set your compileSdkVersionto 21 in your build.gradle file. You also probably want to change your targetSdkVersionto 21.

这可能是因为您没有compileSdkVersion在 build.gradle 文件中将您的设置设置为 21。您可能还想将您的更改targetSdkVersion为 21。

android {
    //...
    compileSdkVersion 21

    defaultConfig {
        targetSdkVersion 21
    }
    //...
}

This requires you to have downloaded the latest SDK updates to begin with.

这要求您首先下载最新的 SDK 更新。

Android Studio SDK Manager

Android Studio SDK 管理器

Once you've downloaded all the updates(don't forget to also update the Android Support Library/Repository, too!) and updated your compileSdkVersion, re-sync your Gradle project.

一旦您下载了所有更新(不要忘记也更新 Android 支持库/存储库!)并更新您的 compileSdkVersion,重新同步您的 Gradle 项目。

Edit: For Eclipse or general IntelliJ users

编辑:对于 Eclipse 或一般 IntelliJ 用户

See reVerse's answer. He has a very thorough walk through!

请参阅反向的答案。他有一个非常彻底的步行!

回答by madhu527

`Follow below steps:

`请按照以下步骤操作:

its working for me.To resolve this issue,

它对我有用。要解决这个问题,

1.Right Click on appcompat_v7 library and select Properties

1.右键单击appcompat_v7库并选择属性

2.Now, Click on Android Option, Set Project Build Path as Android 5.0 (API level 21) Apply Changes.

2.现在,单击Android Option,将项目构建路径设置为Android 5.0 (API level 21) Apply Changes。

3.Now go to project.properties file under appcompat_v7 library,

3.现在转到appcompat_v7库下的project.properties文件,

4.Set the project target as : target=android-21

4.设置项目目标为:target=android-21

5.Now Clean + Build appcompat_v7 library and your projects`

5.Now Clean + Build appcompat_v7 库和你的项目`

回答by vandus

In case you don't want to use API 21 as the target API, and thus you don' t want to use the Material Theme, you have to use an older revision belonging to API 19 >

如果您不想使用 API 21 作为目标 API,因此您不想使用 Material Theme,则必须使用属于 API 19 的旧版本 >

compile "com.android.support:appcompat-v7:19.0.+"

This also helps solving your problem, it only depends on what you want to achieve.

这也有助于解决您的问题,这仅取决于您想要实现的目标。

回答by pepyakin

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

我在 play-services:5.0.89 中遇到过这个问题。升级到 6.1.11 解决了问题。

回答by Gianfranco P.

In Android Studio I was trying to set the compileSdkVersionand targetSdkVersionto 19.

在 Android Studio 中,我试图将compileSdkVersion和设置targetSdkVersion19.

My solution was to replace at the bottom of build.gradle, fromthis:

我的解决办法是在底部的替换build.gradle这样的:

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

To the older version of the appcompat library:

到旧版本的 appcompat 库:

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

回答by live-love

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
  • 右键单击项目
  • 选择属性
  • 单击左侧菜单中的 Android
  • 点击添加
  • 请选择一个图书馆项目

The jar went into Android Dependenciesfolder and this error was fixed.

jar 进入Android Dependencies文件夹,此错误已修复。

回答by mili

I got the same error when I changed the Compile SDK version from API:21 to API:16. The problem was, appcompatversion. 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.+.

当我将编译 SDK 版本从 API:21 更改为 API:16 时,我遇到了同样的错误。问题是,appcompat版本。如果您需要使用旧版本的 android API,那么您也必须更改此 appcompat 版本。就我而言(对于 API:16),我必须使用appcompat-v7:19.+

So I replace dependencies in build.gradleas follows,

所以我将build.gradle 中的依赖替换如下,

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

并确保您的 SDK 上有旧版本的 appcompat 版本 在此处输入图片说明

回答by DoruChidean

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

我是最新的,但仍然出现此错误,不知道为什么,但我认为图像以一种奇怪的方式损坏,替换图像后我摆脱了错误。可能值得尝试使用不同的图像:)

回答by Brendon Sled

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

确保您在 android studio(或 eclipse)中清理您的项目,

It should solve your issues

它应该可以解决您的问题