如何在 Eclipse 中添加 Android Support v7 库? [英] How to add Android Support v7 libraries in eclipse?

本文介绍了如何在 Eclipse 中添加 Android Support v7 库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 Eclipse 中添加 Android Support v7 库?例如,如何将 CardView 添加到 eclipse android 项目中?

How do I add Android Support v7 libraries in eclipse? For example how do I add CardView to an eclipse android project?

注意:这是一个自我回答的问题,所以没有必要浪费你的时间来回答.当然,如果你有什么要补充的,请尽管说.

Note: This was a self answer question, so no need to waste your time making an answer. Of course, if you have anything to add, please do.

推荐答案

来自:https://developer.android.com/tools/support-library/setup.html#libs-with-res

我知道这看起来像很多步骤,但实际上它非常分解,只需要两分钟

I know this looks like a lot of steps, but in reality it's just very broken down and only takes two minutes

要使用 Eclipse 向您的应用程序项目添加包含资源(例如 v7 cardview)的支持库:

To add a Support Library with resources (such as v7 cardview) to your application project using Eclipse:

根据支持库代码创建一个库项目:

Create a library project based on the support library code:

  • 确保您已使用 SDK 管理器下载了 Android 支持库.

  • Make sure you have downloaded the Android Support Library using the SDK Manager.

创建一个库项目并确保所需的 JAR 文件包含在项目的构建路径中:

Create a library project and ensure the required JAR files are included in the project's build path:

选择文件>导入.

选择Existing Android Code Into Workspace,然后点击下一步.

Select Existing Android Code Into Workspace and click Next.

浏览到 SDK 安装目录,然后浏览到 Support Library 文件夹.例如,如果您要添加 cardview 项目,请浏览至 /extras/android/support/v7/cardview/.

Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the cardview project, browse to <sdk>/extras/android/support/v7/cardview/.

单击完成以导入项目.对于 v7 cardview 项目,您现在应该会看到一个名为 android-support-v7-cardview 的新项目.

Click Finish to import the project. For the v7 cardview project, you should now see a new project titled android-support-v7-cardview.

在新建的库项目中,展开libs/文件夹,右键点击每个.jar文件,选择Build Path > Add to Build路径.例如在创建v7 cardview 项目时,将android-support-v7-cardview.jar 文件添加到构建路径中.(根据您的设置,Eclipse 可能已经完成了这四个操作.)

In the new library project, expand the libs/ folder, right-click each .jar file and select Build Path > Add to Build Path. For example, when creating the v7 cardview project, add the android-support-v7-cardview.jar file to the build path. (Depending on your setup, Eclipse may have done this four you already.)

右键单击库项目文件夹,然后选择构建路径 > 配置构建路径.

Right-click the library project folder and select Build Path > Configure Build Path.

Order and Export 选项卡中,检查您刚刚添加到构建路径的 .jar 文件,以便它们可用于依赖于此的项目图书馆项目.例如cardview项目需要你导出android-support-v7-cardview.jar文件.(根据您的设置,Eclipse 可能已经完成了这四个操作.)

In the Order and Export tab, check the .jar files you just added to the build path, so they are available to projects that depend on this library project. For example, the cardview project requires you to export the android-support-v7-cardview.jar file. (Depending on your setup, Eclipse may have done this four you already.)

取消选中Android 依赖项.

点击确定(或应用并关闭)完成更改.

您现在为所选的支持库创建了一个库项目,您可以将其用于一个或多个应用程序项目.

You now have a library project for your selected Support Library that you can use with one or more application projects.

现在将库添加到您的应用程序项目中:

Now add the library to your application project:

  • 在项目资源管理器中,右键单击您的项目并选择属性.

在对话框左侧的类别面板中,选择 Android.

In the category panel on the left side of the dialog, select Android.

窗格中,点击添加按钮.

选择库项目并点击确定.例如,appcompat 项目应列为 android-support-v7-cardview.

Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-cardview.

在属性窗口中,点击确定(或应用并关闭).

In the properties window, click OK (or Apply and Close).

对于某些库,您会收到错误消息,例如

For some libraries, you will get error messages such as

未找到与给定名称android:Widget.Material.ActionButton"匹配的资源.style_base.xml/appcompat_v7/res/values-v21

No resource found that matches the given name 'android:Widget.Material.ActionButton'. styles_base.xml/appcompat_v7/res/values-v21

如果发生这种情况,请记录您在这些错误消息中看到的最高 API 级别(上例中的 v21).然后,在您的库项目的属性中,转到 Android 并将目标 API 设置为该级别(或更高级别),然后清理您的项目.

If that happens, record the highest API level you are seeing in those error messages (v21 in the example above). Then, in the properties of your library project, go to Android and set the target API to that level (or a higher one), then clean your projects.

这篇关于如何在 Eclipse 中添加 Android Support v7 库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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