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

loe*_*chg 374 android gradle xamarin.android android-support-library android-5.0-lollipop

尝试在我的项目中使用最新的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'.
Run Code Online (Sandbox Code Playgroud)

我该如何解决?

reV*_*rse 597

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


Prerequirements

确保您已经下载了最新版本extras以及Android 5.0 SDKSDK-Manager.

SDK Manager的图片


Android Studio

打开build.gradle你的应用程序模块的文件,并将你更改compileSdkVersion为21.基本上没有必要将targetSdkVersionSDK版本更改为21,但建议你应该始终定位最新的Android Build-Version.
最后你的gradle文件将如下所示:

android {
    compileSdkVersion 21
    // ...

    defaultConfig {
        // ...
        targetSdkVersion 21
    }
}
Run Code Online (Sandbox Code Playgroud)

务必在事后同步您的项目.

Android Studio Gradle Sync提醒


日食

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

导入项目后,您将意识到文件夹中的某些文件/res夹带有红色下划线,因为出现以下错误:

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'.
Run Code Online (Sandbox Code Playgroud)

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


IntelliJ IDEA(不使用Gradle)

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

当您尝试构建项目时,您将面临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
Run Code Online (Sandbox Code Playgroud)

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

选择API 21平台

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

  • 我也面临同样的问题,在将目标从target = android-19更改为target = android-21之后,也会在值文件夹dud​​e上出现错误 (2认同)

loe*_*chg 123

这很可能是因为您没有compileSdkVersion在build.gradle文件中将21 设置为21.你也可能想把你改成targetSdkVersion21.

android {
    //...
    compileSdkVersion 21

    defaultConfig {
        targetSdkVersion 21
    }
    //...
}
Run Code Online (Sandbox Code Playgroud)

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

Android Studio SDK Manager

下载完所有更新后(不要忘记同时更新Android支持库/存储库!)并更新您的compileSdkVersion,重新同步您的Gradle项目.

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

请参阅reVerse的回答.他有一个非常彻底的步行!

  • 这是正确的答案.升级到21需要这个新的appcompat依赖项,你需要下载第12版的播放服务. (2认同)

mad*_*527 22

`按照以下步骤:

它为我工作.要解决这个问题,

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

2.现在,点击Android选项,将项目构建路径设置为Android 5.0(API级别21)应用更改.

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

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

5.Now Clean +构建appcompat_v7库和你的项目

  • 你可以找到appcompat_v7 lib:adt-bundle-windows-x86_64 - > sdk - >\extras\ - > android\ - > support - > v7 (2认同)

van*_*dus 12

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

compile "com.android.support:appcompat-v7:19.0.+"
Run Code Online (Sandbox Code Playgroud)

这也有助于解决您的问题,它只取决于您想要实现的目标.


pep*_*kin 10

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


Gia*_* P. 8

在Android Studio中,我试图设置compileSdkVersiontargetSdkVersion19.

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

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

到旧版本的appcompat库:

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