gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:49:33 25 4
gpt4 key购买 nike

在我的项目中尝试使用最新的 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'.

我该如何解决这个问题?

最佳答案

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


先决条件

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

Picture of the SDK Manager


Android 工作室

打开你的app-module的build.gradle文件,把compileSdkVersion改成21,targetSdkVersion基本没必要改SDK 版本为 21,但建议您始终使用 target the latest android Build-Version .
最后你的 gradle-file 看起来像这样:

android {
compileSdkVersion 21
// ...

defaultConfig {
// ...
targetSdkVersion 21
}
}

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

Android Studio Gradle Sync reminder


eclipse

在 Eclipse 中使用 v7-appcompat 时,您必须将其用作库项目。仅将 *.jar 复制到您的 /libs 文件夹是不够的。请阅读 this (click) developer.android.com 上的分步教程,以便了解如何正确导入项目。

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

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

解决方案

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


IntelliJ IDEA(不使用 Gradle)

与 Eclipse 类似,仅使用 android-support-v7-appcompat.jar 是不够的;您必须将 appcompat 作为模块导入。在 StackO-Post (click) 上阅读更多相关信息.
(注意: 如果你只使用 .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

解决方案

右击appcompat模块-->打开模块设置(F4)-->[Dependency Tab]从下拉列表中选择Android API 21 Platform-->应用

Select API 21 Platform

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

关于android - appcompat-v7 :21. 0. 0': No resource found that matches the given name: attr ' android:actionModeShareDrawable',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26431676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com