AppCompat v7 r21在values.xml中返回错误?

284

我正在使用Android Studio,在Gradle文件中添加compile "com.android.support:appcompat-v7:21.0.0"后,出现了大量的错误:

C:\Users\WindowsSucks\AndroidStudioProjects\MMMeds\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'.
C:\Users\WindowsSucks\AndroidStudioProjects\MMMeds\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0\res\values-v14\values.xml
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
Error:(9, 21) No resource found that matches the given name: attr 'android:actionModeShareDrawable'.
C:\Users\WindowsSucks\AndroidStudioProjects\MMMeds\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0\res\values-v21\values.xml
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:TextAppearance.Material.Body1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Body2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Caption'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display1'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display2'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display3'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Display4'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Headline'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Large.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Medium.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Menu'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name '@android:TextAppearance.Material.SearchResult.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Small.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Subhead'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Menu'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title.Inverse'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionMode.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionMode.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Large'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.PopupMenu.Small'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Button'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Subtitle'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.ActionBar.Title'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:ThemeOverlay.Material'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:ThemeOverlay.Material.ActionBar'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:ThemeOverlay.Material.Dark'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:ThemeOverlay.Material.Dark.ActionBar'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:ThemeOverlay.Material.Light'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionBar.TabText'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionBar.TabView'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton.CloseMode'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ActionButton.Overflow'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.AutoCompleteTextView'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.DropDownItem.Spinner'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabText'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabText'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.ActionBar.TabView'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.AutoCompleteTextView'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Light.PopupMenu'.
Error:(298, 21) No resource found that matches the given name: attr 'android:overlapAnchor'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListPopupWindow'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListView.DropDown'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ListView'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.PopupMenu'.
Error:(298, 21) No resource found that matches the given name: attr 'android:overlapAnchor'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ProgressBar'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.ProgressBar.Horizontal'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Spinner'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Material.Toolbar.Button.Navigation'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Dialog'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light'.
Error:Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Material.Light.Dialog'.
Error:(144, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(146, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(147, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(145, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(142, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(143, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(144, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(146, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(147, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(145, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(142, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(143, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(144, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(146, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(147, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(145, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(142, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(143, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.
Error:(144, 21) No resource found that matches the given name: attr 'android:colorAccent'.
Error:(146, 21) No resource found that matches the given name: attr 'android:colorControlActivated'.
Error:(147, 21) No resource found that matches the given name: attr 'android:colorControlHighlight'.
Error:(145, 21) No resource found that matches the given name: attr 'android:colorControlNormal'.
Error:(142, 21) No resource found that matches the given name: attr 'android:colorPrimary'.
Error:(143, 21) No resource found that matches the given name: attr 'android:colorPrimaryDark'.

所有这些似乎都出现在:

\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0\res\values-v11\values.xml
and
\app\build\intermediates\exploded-aar\com.android.support\appcompat-v7\21.0.0\res\values-v21\values.xml

6
你的compileSdkVersion设置为21了吗? - ianhanniballake
没有,我有“compileSdkVersion 20,buildToolsVersion“20.0.0””我需要将buildToolsVerison更改为21吗?@ianhanniballake - Michael Garber
在使用Eclipse时也会出现错误。 - Iftikar Urrhman Khan
你应该始终将依赖更新到最新版本,例如appcompat-v7:21.0.3。 - IgorGanapolsky
1
@IgorGanapolsky 在 values-v21 中的 <style name="AppBaseTheme" parent="android:Theme.Material.Light"></style> 中无法解析符号 'android:Theme.Material.Light'。 - Pankaj Nimgade
22个回答

427

AppCompat v21构建的主题需要API 21(Android 5.0)中提供的新API。要使用AppCompat编译您的应用程序,您还必须编译针对API 21。推荐的API 21编译/构建设置是compileSdkVersion21buildToolsVersion21.0.1(目前是最高版本 - 您总是希望使用最新的构建工具)。


6
这样做会让我的应用程序与旧版本不兼容吗?我希望我的应用程序能够向后兼容到SDK 15。 - Michael Garber
45
compileSdkVersionminSdkVersion(控制您的应用程序可以运行的最低级别)和targetSdkVersion(控制任何自动应用的向后兼容功能 - 如果您尚未在最新的API上测试过应用程序,则很重要)完全不同。请注意,不要改变原文的意思。 - ianhanniballake
18
如果您已经尝试过这些步骤,但仍然遇到错误,有什么建议吗?我将 compileSdkVersion 设置为 21,buildToolsVersion 设置为 21.0.1,但还是不行。 - Tom
7
很遗憾,对我来说并没有起作用。 我现在使用的是 21.0.2 版本,但仍然没有运气。 - Tom
2
谢谢@Sver,不幸的是我已经删除了所有库,但没有成功。只有@shider的解决方案,将版本更改为appcompat-v7:20.0.0才有效,但该版本并没有我要寻找的所有功能,所以这是无意义的。我还确认在使用新的Build Tools 21创建的空白项目上也会出现此问题,其中包含appcompat-v7:21.0.0 - Tom
显示剩余18条评论

43

确保在项目文件夹appcompat_v7文件夹的project.properties文件中目标(指定目标Android版本)的相同(最好是最新版本)。

your_project/project.properties文件中:

target=android-21 android.library.reference.1=../appcompat_v7

以及

appcompat_v7/project.properties文件中:

target=android-21 android.library=true

完成上述步骤后,不要忘记进行清理操作


1
谢谢GiriB!这对我很有帮助。我的项目的目标构建版本低于appcompat文件夹。 - GraSim
谢谢@GiriB,这对我也有用。我的项目比appcompat lib项目的目标构建版本低。 - Bharat Dodeja

18

我把 gradle.build 文件中的 compile 'com.android.support:appcompat-v7:21.0.0' 改成了 compile 'com.android.support:appcompat-v7:20.0.0',这样就解决了我的问题。


1
是的,它可以工作。但会阻止您使用appcompat-v7:21.0.0。 - Sver
这是我唯一有效的解决方案,但它有限制。我不确定为什么会发生这种情况。 - Tom
@Sver,在values-v21文件夹下的<style name="AppBaseTheme" parent="android:Theme.Material.Light"></style>中,无法解析符号'android:Theme.Material.Light'。 - Pankaj Nimgade

12

如果您使用的是Android Studio,请前往 文件-->项目结构 在属性选项卡中将编译SDK版本更改为AP1 21,构建工具版本更改为可用的最高版本。 然后刷新Gradle


这个就是它! - mimoralea

7

我将编译SDK版本更改为API级别21,这样问题就得到了解决。但是,我在将应用程序部署到我的设备时遇到了其他问题。我将最小API级别更改为所需目标,问题得到了解决。

如果有人再次遇到此问题,请注意。


4

将你的编译sdk更改为23。这对我有用。


4
只需选择目标API级别为21进行编译,点击应用 -> 点击确定清理构建项目并运行它。

同样的截图


4

我的解决方案是使用其他版本进行编译。

build.gradle (app)

compileSdkVersion 21

祝你好运


3

我投票给那些能像我一样解决问题的人。 我曾经和你一样遇到了这个问题,花费了很多时间才得到正确的答案。 请进行测试。

升级整个SDK,更新21.0.2版本也包括来自Google Services Play的更新。 升级所有内容。 在你的工作空间中删除文件夹(android-support-v7-AppCompat)和(google-play-services_lib)。

重新导入这些项目到IDE并选择再次将它们复制到你的工作空间。

对于项目(google-play-services_lib),执行刷新和构建操作。

**** ***** 问题 对于项目(android-support-v7-AppCompat),标记5.0 API,然后进行刷新和构建。

在他的项目中,在属性、Android、导入库(android-support-v7-AppCompat)和(google-play-services_lib)之后,进行刷新和构建。


在values-v21中的<style name="AppBaseTheme" parent="android:Theme.Material.Light"></style>中无法解析符号'android:Theme.Material.Light'。 - Pankaj Nimgade

3

如果您不想使用API 21,可以使用旧版本的appcompact库,使用旧的app compact库而不更新它。

您可以通过以下简单步骤实现:

1)提取完整sdk和eclipse捆绑包的下载版本。

2)只需从中导入appCompact库即可。

现在您已经完成了。


@Perroloco 你没听懂吗? - DjP
这是AppCompat。Compat是“compatible/compatibility”的缩写。 :) - SlashG

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接