Android - SPLessons

Android Support Library

Home > Lesson > Chapter 14
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Android Support Library

Android Support Library

In this chapter, we will make you understand about the Android Support Library package and how it works. The Android Support Library package contains several code libraries that provide backward-compatible versions of Android framework APIs and features that are available through the library APIs. Android v4 support and v7 appcompat libraries support a wide range of Android versions and provide APIs for recommended user interface patterns. To use any of the following libraries, you must download the library files to your Android SDK installation. Downloading the Support Libraries: The Android Support Library package is provided as a supplemental download to the Android SDK and is available through the Android SDK Manager. To download the Support Library through the SDK Manager, you need to follow the steps given below: 1. Start the Android SDK Manager 2. In the SDK Manager window, expand the Extras folder 3. Check the Android Support Library 4. Click the Install packages button. After downloading, the tool installs the Support Library files in the existing Android SDK directory. The library files are located in the sub-directory of your SDK: <sdk>/extras/android/support/ directory. Choosing Support Libraries: Before adding a Support Library to your application, decide what features you want to include and the lowest Android versions you want to support. To add a Support Library without resources to your application project: 1.  Make sure you have downloaded the Android Support Library using the SDK Manager. 2. Create a libs/ directory in the root of your application project. 3. Copy the JAR file from your Android SDK installation directory ( <sdk>/extras/android/support/v4/android-support-v4.jar) into your application's project libs/directory. 4. Right click the JAR file and select Build Path > Add to Build Path. To add a Support Library with resources (such as v7 appcompat for action bar) to your application project: Create a library project based on the support library code: 1. Make sure you have downloaded the Android Support Library using the SDK Manager. 2. Create a library project and ensure the required JAR files are included in the project's build path: 1. Select File > Import. 2. Select Existing Android Code Into Workspace and click Next. 3. Browse to the SDK installation directory and then to the Support Library folder. For example, if you are adding the appcompatproject, browse to <sdk>/extras/android/support/v7/appcompat/. 4. Click Finish to import the project. For the v7 appcompat project, you should now see a new project titled android-support-v7-appcompat. 5. 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 the v7 appcompat project, add both the android-support-v4.jar and android-support-v7-appcompat.jar files to the build path. 6. Right-click the library project folder and select Build Path > Configure Build Path. 7. In the Order and Export tab, check the .jar files you just added to the build path, so they are available to the projects that depend on this library project. For example, the appcompat project requires you to export both the android-support-v4.jar and android-support-v7-appcompat.jar files. 8. Uncheck Android Dependencies. 9. Click OK to complete the changes. You now have a library project for your selected Support Library that you can use with one or more application projects. Add the library to your application project: 1. In the Project Explorer, right-click your project and select Properties. 2. In the category panel on the left side of the dialog, select Android. 3. In the Library pane, click the Add button. 4. Select the library project and click OK. For example, the appcompat project should be listed as android-support-v7-appcompat. 5. In the properties window, click OK. Manifest Declaration Changes: You should update the android:minSdkVersion element of the <uses-sdk> tag in the manifest to the new, lower version number, as shown below:
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="17" />
The following are the support libraries that are supported by android. 1. v4 Support Library This library is designed to be used with Android 1.6 (API level 4) and higher  version. It includes the largest set of APIs compared to the other libraries, including support for application components, user interface features, accessibility, data handling, network connectivity, and programming utilities. 2. v7 Support Libraries There are several libraries designed to be used with Android 2.1 (API level 7) and higher version. These libraries provide specific feature sets and can be included in your application independently from each other. Following are the V7 libraries: V7 appcompat library V7 cardview library V7 gridlayout library v7 mediarouter library v7 palette library v7 recyclerview library 3. v8 Support Library This library is designed to be used with Android 2.2 (API level 8) and higher version. This library provides specific feature sets and can be included in your application independently from other libraries. v8 renderscript library is the V8 support library. 4. v13 Support Library This library is designed to be used for Android 3.2 (API level 13) and higher. It adds support for the Fragment user interface pattern with the (FragmentCompat) class and additional fragment support classes. 5.Annotations Support Library The Annotation package provides APIs to support adding annotation metadata to your apps. After you download the Android Support Libraries, the library is located in the <sdk>/extras/android/support/annotations directory. 6.Design Support Library The Design package provides APIs to support adding material design components and patterns to your apps. The Design Support library adds support for various material design components and patterns for app developers to build upon, such as navigation drawers, floating action buttons (FAB), snackbars, and tabs. After you download the Android Support Libraries, the library is located in the <sdk>/extras/android/support/design directory. 7.Multidex Support Library This library provides support for building apps with multiple Dalvik Executable (DEX) files. Apps that refer more than 65536 methods are required to use multidex configurations. After you download the Android Support Libraries, the library is located in the <sdk>/extras/android/support/multidex/ directory.