eclipse 放弃支持库 v7。我做错了什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19950866/
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
Giving up on support library v7. What did I wrong?
提问by Mister Smith
I need to add the action bar for devices 2.3 and higher.
我需要为 2.3 及更高版本的设备添加操作栏。
I recently knew about the appcompat v7 support library, which does exactly that.
我最近知道 appcompat v7 支持库,它正是这样做的。
I've followed the Support library setup guide, step by step, cleaned, built, and cleaned again, restarted eclipse, upgraded SDK and plugin to the last version (just to realise that SDK build tools v19 are broken, so I had to delete them). Two hours later I'm still unable to build my project. I'm getting these errors:
我按照Support library setup guide,一步步清理,构建,再清理,重启eclipse,将SDK和插件升级到最新版本(才发现SDK构建工具v19坏了,只好删了他们)。两个小时后,我仍然无法构建我的项目。我收到这些错误:
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:33: error: Error: No resource found that matches the given name: attr 'android:windowActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:42: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v11\themes_base.xml:44: error: Error: No resource found that matches the given name: attr 'android:windowActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:31: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:41: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:57: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:67: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:83: error: Error retrieving parent for item: No resource found that matches the given name 'android:Theme.Holo.Light.DarkActionBar'.
[2013-11-13 00:00:00 - FooProject] D:\foo_project\android-support-v7-appcompat\res\values-v14\themes_base.xml:94: error: Error: No resource found that matches the given name: attr 'android:actionBarWidgetTheme'.
And I've tried everything in the following questions, to no avail:
Adding Support Libraries to Android project
After setting up android-support-v7-appcompat R.java is missing
Android Support Library v7: Error retrieving parent for item
Can't Find Theme.AppCompat.Light for New Android ActionBar Support
How to resolve the error "No resource found that matches the given name" when adding library v7 AppCompat in Eclipse?
我已经尝试了以下问题中的所有内容,但均无济于事:
将支持库添加到 Android 项目
后设置 android-support-v7-appcompat R.java 缺少
Android 支持库 v7:
无法找到项目的检索父项时出错Theme.AppCompat.Light for New Android ActionBar Support
如何解决在 Eclipse 中添加库 v7 AppCompat 时“找不到与给定名称匹配的资源”的错误?
I'm not saying those answers are not valid, just that for some reason they didn't work for me (I think it's because Google hates me).
我并不是说这些答案无效,只是出于某种原因它们对我不起作用(我认为这是因为 Google 讨厌我)。
Here are my manifest lines for the target sdk:
这是我的目标 sdk 清单行:
For the library:
对于图书馆:
<uses-sdk android:minSdkVersion="7"/>
and for the main project:
对于主要项目:
<uses-sdk android:targetSdkVersion="19" android:minSdkVersion="8"/>
Tried every possible combination, cleaning and building after each change, and still no luck.
在每次更改后尝试了所有可能的组合,清理和构建,但仍然没有运气。
Looks like this is a problem related to Holo. I really don't need Holo at all, only ActionBar. For now I'm just switching to ActionBarSherlock, which worked well for me in the past. But I'd really like to know what am I doing wrong, why something does not work despite I've spent a considerable ammount of time researching the issue. Why so much pain in integrating a library that should be usable out of the box.
看起来这是一个与 Holo 相关的问题。我真的根本不需要 Holo,只需要 ActionBar。现在我只是切换到 ActionBarSherlock,它在过去对我很有效。但我真的很想知道我做错了什么,尽管我花了大量时间研究这个问题,但为什么有些东西不起作用。为什么在集成一个开箱即用的库时会如此痛苦。
Is it possible to get ONLY action bar with the support v7 library?
是否可以通过支持 v7 库获得唯一的操作栏?
回答by Mister Smith
Finally got it working.
终于让它工作了。
When adding ActionBarSherlock, the same kind of errors where appearing in the console.
添加 ActionBarSherlock 时,在控制台中出现相同类型的错误。
I've edited the project.properties
file (yeah, that one with the comment "This file is automatically generated by Android Tools. Do not modify this file -- YOUR CHANGES WILL BE ERASED")
Build target was set to 8, changed it to 16 and now it compiles with both ABS and appcompat v7.
我已经编辑了该project.properties
文件(是的,带有注释“此文件由 Android 工具自动生成。不要修改此文件——您的更改将被删除”)构建目标设置为 8,将其更改为 16 和现在它同时使用 ABS 和 appcompat v7 进行编译。
UPDATE:
Here's how to do it the right way:
https://stackoverflow.com/a/3343050/813951
更新:
以下是正确方法:https:
//stackoverflow.com/a/3343050/813951
回答by RRTW
Have to look at ActionBarSherlock, it really helps, since your root request is add the action bar for devices 2.3 and higher
必须查看ActionBarSherlock,它确实有帮助,因为您的根请求是为设备 2.3 及更高版本添加操作栏
In my project, it works with android 2.2 to 4.x
在我的项目中,它适用于 android 2.2 到 4.x
回答by Daniel Dudek
When using Android Studio and build.gradle setup: bump up compileSdkVersion
>= 14.
当使用 Android Studio 和 build.gradle 设置时:bump up compileSdkVersion
>= 14。