原文地址:http://developer.android.com/tools/support-library/setup.html

如何在你的开发项目中安装Android Support Library,取决于你要使用哪些功能,以及你要在你的应用中支持哪个范围的Android平台版本。

原文:How you setup the Android Support Libraries in your development project depends on what features you want to use and what range of Android platform versions you want to support with your application.

这个文档指导你下载Support Library包,并向你的开发环境中添加库。

原文:This document guides you through downloading the Support Library package and adding libraries to your development environment.

下载Support Library

Android Support Library包是作为Android SDK的补充下载提供的,并且在AndroidSDK Manager中是可用的。遵循以下说明来获取Support Library文件。

 

原文:The Android Support Library package is provided as a supplemental download to the Android SDK and is available through the Android SDK Manager. Follow the instructions below to obtain the Support Library files.

通过SDK Manager获取Support Library:

1.打开Android SDK Manager

2.在SDK Manager窗口,滚动到Package List的末尾,找到Extra文件夹,如果需要的话打开文件夹显示它的内容。

3.选择Android Support Library项目。

注意:如果你使用的是Android Studio开发,选择并安装Android Support Repository项目而不是Android Support Library项目。

4.点击Install packages按钮。

下载完成后,SDK会将Support Library文件安装到你已经存在的Android SDK目录下。库文件位于SDK的如下子目录:<sdk>/extras/android/support/目录。

 

原文:After downloading, the tool installs the Support Library files to your existing Android SDK directory. The library files are located in the following subdirectory of your SDK: <sdk>/extras/android/support/ directory.

 

选择Support Library

 
在添加一个Support Library到你的项目之前,想好你要包含哪些功能,以及你要支持的最低Android版本是多少。查看Support Library Features以获取更多关于不同库提供的功能的信息。
 
原文:Before adding a Support Library to your application, decide what features you want to include and the lowest Android versions you want to support. For more information on the features provided by the different libraries, see Support Library Features.

 

 

添加Support Library

 

为了使用Support Library,你必须在开发环境中修改应用项目的classpath依赖关系。并且你必须为将要使用的每一个Support Library都执行一下上述步骤。

原文:In order to use a Support Library, you must modify your application's project's classpath dependencies within your development environment. You must perform this procedure for each Support Library you want to use.

除了可编译的代码类,一些Support Library包含了资源,比如图片或XML文件。例如,v7 appcompat和 v7 gridlayout库包含一些资源。

原文:Some Support Libraries contain resources beyond compiled code classes, such as images or XML files. For example, thev7 appcompat and v7 gridlayout libraries include resources.

如果你不确定一个库是否包含资源,查看Support Library Features页面。下面的章节描述了如何添加一个包含或不包含资源的Support Library到你的应用项目中。

原文:If you are not sure if a library contains resources, check the Support Library Features page. The following sections describe how to add a Support Library with or without resources to your application project.

 

 

添加不带资源的library

 

添加一个不包含资源的Support Library到你的应用项目:

原文:To add a Support Library without resources to your application project:

利用Eclipse

  1. 确保你已经利用SDK Manager下载了Android Support Library 。
  2. 在你的项目的根目录下创建一个libs/目录。
  3. 从你的Android SDK安装目录(例如,<sdk>/extras/android/support/v4/android-support-v4.jar)下拷贝JAR文件到你项目的libs/目录下。
  4. 右键点击JAR文件并选择Build Path > Add to Build Path。

利用Android Studio

  1. 确保你已经利用SDK Manager下载了Android Support Repository 。
  2. 打开项目中的 build.gradle文件。
  3. 添加Support Library到dependencies部分。例如,如果添加v4 Support Library,加入下面一行:
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. dependencies {  
  2.     ...  
  3.     compile "com.android.support:support-v4:18.0.+"  
  4. }  

 

添加带资源的library

 

添加一个包含资源(例如带有Action Bar的v7 appcompat的Support Library到你的应用项目:
原文:To add a Support Library with resources (such as v7 appcompat for action bar) to your application project:

 

利用Eclipse

创建一个基于support library代码的 library project
  1. 确保你已经利用 SDK Manager下载了Android Support Library
  2. 创建一个library项目并且确保需要的JAR文件包含在了项目的build path中:
    1. 选择File > Import
    2. 选择Existing Android Code Into Workspace 并点击Next
    3. 浏览SDK安装目录,并进入Support Library目录下。例如,如果你要添加appcompat项目,浏览 <sdk>/extras/android/support/v7/appcompat/
    4. 点击Finish引入项目。对于v7 appcompat项目,你将看到一个标题为android-support-v7-appcompat的新项目。
    5. 在新项目中,展开libs/ 文件夹,右键点击每一个.jar文件,并选择Build Path > Add to Build Path。例如,当创建v7 appcompat项目时,同时将android-support-v4.jarandroid-support-v7-appcompat.jar文件添加到build path中。
    6. 右键点击library项目文件夹并选择Build Path > Configure Build Path
    7. 在Order and Export选项中,在刚刚添加到build path中的.jar文件上打勾,这时这些文件成为项目可用的了并依赖于这个library项目。例如,appcompat项目要求同时导出android-support-v4.jarandroid-support-v7-appcompat.jar文件。
    8. 去掉Android Dependencies上的对勾。
    9. 点击OK完成设置。
现在你拥有了一个包含你选择的Support Library的library项目,你可以在一个或多个应用项目中利用这个Support Library。
原文:You now have a library project for your selected Support Library that you can use with one or more application projects.
 
向你的应用工程(译者注:需要加入Support Library的工程)添加库:
原文:Add the library to your application project:
  1. 在项目浏览器中右键单击你的项目,选择Properties
  2. 在左边的分类面板中,选择Android
  3. 在Library面板中,点击Add
  4. 选择库项目,然后点击OK。例如,appcompat项目会在列表中显示为android-support-v7-appcompat
  5. 在properties窗口中,点击OK

利用Android Studio

  1. 确保你利用SDK Manager下载了Android Support Repository
  2. 打开项目中的build.gradle文件。
  3. 将support library功能项目标识符添加到dependencies部分。例如,为了包含appcompat项目,需要将compile "com.android.support:appcompat-v7:18.0.+"添加到dependencies部分。如下:
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. dependencies {  
  2.     ...  
  3.     compile "com.android.support:appcompat-v7:18.0.+"  
  4. }  

使用Support Library的API

对目前framework API提供支持的Support Library类,一般都与framework中的类名相同,但是位于android.support类包中,或者有一个*Compat后缀。

原文:Support Library classes that provide support for existing framework APIs typically have the same name as framework class but are located in the android.support class packages, or have a *Compat suffix.

警告:当使用Support Library中的类的时候,确定你从适当的包中引入这些类。例如,当应用ActionBar类的时候:

 

  • 当使用Support Library时:android.support.v7.app.ActionBar
  • 当只为API 11或更高级别开发的时候:android.app.ActionBar

 

 

原文:Caution: When using classes from the Support Library, be certain you import the class from the appropriate package. For example, when applying the ActionBar class:

  • android.support.v7.app.ActionBar when using the Support Library.
  • android.app.ActionBar when developing only for API level 11 or higher.
注意:当包含了Support Library在你的项目中后,我们强烈推荐你使用ProGuard工具准备你的应用APK发布。除了保护你的源代码外,ProGuard工具还可以从你包含到应用中的任何库中去除无用的类,这样可以使你的应用大小在下载的时候尽可能的小。要获取更多信息,请查看 ProGuard

原文:Note: After including the Support Library in your application project, we strongly recommend using the ProGuard tool to prepare your application APK for release. In addition to protecting your source code, the ProGuard tool also removes unused classes from any libraries you include in your application, which keeps the download size of your application as small as possible. For more information, see ProGuard.

在Android开发者training classesguides和示例中,提供了一些使用Support Library功能的更多指南。查看API参考中的android.support包,以获取更多关于单个Support Library类和方法的信息。

原文:Further guidance for using some Support Library features is provided in the Android developer training classesguides and samples. For more information about the individual Support Library classes and methods, see the android.support packages in the API reference.

Manifest声明的改变

 
如果你正在利用Support Library增加目前应用的向下兼容性到一个Android API的早期版本,确保更新你应用的manifest。特别的,你要更新manifest中<uses-sdk>标签的android:minSdkVersion元素,改成一个新的,更低的版本号,如下:
原文: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. Specifically, you should update the android:minSdkVersion element of the <uses-sdk> tag in the manifest to the new, lower version number, as shown below:
[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <uses-sdk  
  2.     android:minSdkVersion="7"  
  3.     android:targetSdkVersion="17" />  

这个改变通知Google Play你的应用可以被安装在Android 2.1(API level 7)或更高的版本的设备中。

原文:This change tells Google Play that your application can be installed on devices with Android 2.1 (API level 7) and higher.

注意:如果你在项目中包含了v4 support和v7 appcompat库,你需要指定最小SDK版本为7(而不是4)。你引入到应用的最高级别的support library决定了它可以操作的最低的API版本。(译者注:这句话是指当你同时引入了多个包的情况,比如,v7比v4版本更高,所以可以操作的最小SDK版本是7)

原文:Note: If you are including the v4 support and v7 appcompat libraries in your application, you should specify a minimum SDK version of "7" (and not "4"). The highest support library level you include in your application determines the lowest API version in which it can operate.

代码示例

每一个Support Library都包含了代码示例来帮助你开始使用support API。代码示例包含在从SDK Manager的下载中,并被放在了Android SDK安装目录中,如下所列:
原文:Each Support Library includes code samples to help you get started using the support APIs. The code is included in the download from the SDK Manager and is placed inside the Android SDK installation directory, as listed below:
 
  • 4v Samples: <sdk>/extras/android/support/samples/Support4Demos/
  • 7v Samples: <sdk>/extras/android/support/samples/Support7Demos/
  • 13v Samples: <sdk>/extras/android/support/samples/Support13Demos/
  • App Navigation: <sdk>/extras/android/support/samples/SupportAppNavigation/

欢迎转载,转载请注明出处:http://blog.csdn.net/crazybigfish/article/details/18554201
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()