将支持库添加到Android项目 [英] Adding Support Libraries to Android project

查看:167
本文介绍了将支持库添加到Android项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我有这么难的时间进入Android开发的摇摆?多年来,我一直在开发各种语言,而且由于某种原因,似乎超越了Android的jeez-i-still-feel-a-total-noob舞台。



所以我试图在我的Android 2.3.3项目中添加一个Action Bar。没问题吧? Android开发者网站有一个很好的和明确的文章,解释如何做到这一点。当然这涉及到添加appcompat v7支持库。没有问题,即使在此页面上分一步说明。但是,就像在Android中的每一个这样的练习一样,我发现你可以完全按照这个页面来告诉你做什么,但是如果没有大量的Google搜索来修复你之前遇到的错误,那么它仍然无法正常工作。 >

所以我按照上述链接中的使用资源添加库一节中的使用Eclipse下的步骤。我得到的第一个错误是无法解析目标android-16。没问题,这个我可以为自己弄清楚,但我很好奇,有没有什么文件我一直在追踪,这将建议我,我需要Android 4.1.2(API16)安装?我刚刚阅读它,还是应该自己知道,为了做我想做的事情,我需要API16?



没关系,在至少我可以解决这个问题,但是我得到一个新的问题。一旦我将android-support-v7-compat库添加到我的项目中,然后单击确定按钮,控制台输出就会出现错误,第一个是:


C:... \android-support-v7-appcompat\res\values-v14\styles_base.xml:24:
错误:检索项目的父项时出错:没有资源发现
匹配给定的名称android:Widget.Holo.ActionBar。


而另外60个错误是相似的,但对于不同的给定名称。



如果有人能帮助我,我真的很感激。很明显,我想知道如何解决这个特殊的问题,但是如果有人能给我一些关于如何超越这个非常令人沮丧的学习这个新开发环境的技巧,那么我会非常感激。除了按照Android开发人员网站上的说明逐步执行,我应该做的不同,不会遇到这样的错误?

解决方案

好的,我想我应该发表一个答案,因为我最终设法解决了我自己的问题。



原来我必须使用Android 4.2.2的构建目标,无论我是专门为Android 2.3.3开发的事实 - 我的意思是,这就是为什么我使用支持库毕竟。我想象可能有一些其他较低的目标(但高于2.3.3)仍然可以工作,我刚刚使用了我安装的最高的目标,并解决了这个问题。



如何通过Android Developers网站上的分步说明了解这一点,对我来说是一个谜。我决定尝试更改targetSdkVersion的原因是因为页面中引用的最后一节,一>。它显示为如果您使用支持库增加现有应用程序与较早版本的Android API的向后兼容性,请确保更新应用程序的清单。现在我没有增加我现有应用程序的向后兼容性。我正在改变目标2.3.3的现有应用程序,以便能够包含一个Action Bar(似乎更像forward compatibility)。我试图升级targekSdkVersion,尽管我是出于想法,而且看起来有效。


Why am I having such a hard time getting into the swing of Android development? I've been developing in various languages over the years and, for some reason, just can't seem to get beyond that "jeez-i-still-feel-a-total-noob" stage with Android.

So I'm trying to add an Action Bar to my Android 2.3.3 project. No problem, right? The Android developers website has a nice and clear article explaining exactly how to do it. Of course it involves adding the appcompat v7 support library. No problem, even this is documented step-by-step on this page. But, as with just about every such exercise in Android, I find that you can do exactly what the page tells you to do, it still won't work without significant amount of Googling to fix the errors that you encounter afterwards.

So I've followed the steps under "Using Eclipse" in the section "Adding libraries with resources" in the above link. The first error I get is Unable to resolve target 'android-16'. No problem, this one I could figure out for myself but I'm curious, is there anything in the documents I've been following that would have suggested to me that I need Android 4.1.2 (API16) installed? Did I just read right over it or should I have known by myself that, to do what I'm trying to do, I would need API16?

Never mind, at least I can fix that but then I get a new problem. As soon as I add the android-support-v7-compat library to my project and click the OK button, the console output lights up with errors, the first one being:

C:...\android-support-v7-appcompat\res\values-v14\styles_base.xml:24: error: Error retrieving parent for item: No resource found that matches the given name 'android:Widget.Holo.ActionBar'.

and the other 60 odd errors are similar but for different given names.

I would really appreciate if anyone could help me out here. Obviously I'd like to know how to solve this particular problem but if anyone could give me some tips on how to get past this very frustrating stage of learning this new development environment, I would be ever so thankful. What is it that I should have done differently not to run into these kinds of errors, other than following the instructions on the Android Developers website step by step?

解决方案

OK, I guess I should post an answer as I've eventually managed to solve my own problem.

It turns out I have to use a build target of Android 4.2.2, regardless of the fact that I'm specifically developing for Android 2.3.3 - I mean, that's why I'm using support libraries after all. I imagine it might be possible that some other lower target (but higher than 2.3.3) would still work I just used the highest one I have installed and it solved the problem.

How I was supposed to know this from following the step-by-step instructions on the Android Developers website is a mystery to me. The reason I decided to try changing the targetSdkVersion was because of the final section in the page referenced in the question. It reads "If you are increasing the backward compatibility of your existing application to an earlier version of the Android API with the Support Library, make sure to update your application's manifest." Now I'm not increasing the backward compatibility of my existing application. I'm changing an existing application that targets 2.3.3 to be able to include an Action Bar (seems more like "forward compatibility"). I tried upgrading the targekSdkVersion though as I was out of ideas and lo and behold, it worked.

这篇关于将支持库添加到Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆