Support Library Samples in the Android SDK
Update: The Android SDK no longer provides sample projects for download. All samples are now provided online. Therefore this article is archived and provided for historical reasons only.
How to Load and Run the Android Support Library Demos
This tutorial will show you how to load the samples provided with the Android SDK that demonstrate using the Android Support Library, some refer to it as Android Support Package or the Android Compatibility Package. The online Android developer documentation does not give enough detail on getting the Support Library demos running, this article covers that shortfall.
What is the Android Support Library?
The Android Operating System (OS) is updated regularly to add new features, support new devices and implement new ideas. This requires changes and additions to the Application Programming Interface (API). For apps to be widely used they need to run on devices with earlier APIs as well as devices that have the new features. To help developers achieve this Google provides a Support Library that allows some of the newer API features to be used on earlier devices.
For example when Android version 3.0 (Honeycomb, API 3.0) was released, to support tablet style devices, it provided the new Fragment class. The use of Fragments allows a User Interface (UI) to be divided into smaller sections allowing for improved app design when dealing with larger screens. A tablet app may have a screen composed of three Fragments, when that app is run on a device with a small screen the three Fragments may represent three separate screens. To run an app based on Fragments on a device with a version of Android lower that 3.0, i.e. API 10 or earlier, the Android Support Library is required. It has implementations of some of the new Android APIs to allow earlier devices to run code written for the new APIs, helping with an apps backwards compatibility. (Note that this differs from Android Compatibility Mode which is what new devices use to run old apps.)
Android Support Library Installation
The Android Support Library and compatibility samples are installed via the SDK Manager. If a full install of the Android SDK was done then in the Android SDK folder the compatibility files are in android-sdk/extras/android/compatibility. If the Android Support Library is not installed simply run SDK Manager (SDK Manager.exe on Windows). Open the Extras folder. Select Android Support Library then click the Install 1 package button (accepting the licence agreement).
The Android SDK has available two versions of the Support LIbrary:
- android-support-v4.jar – Version 4 is for apps aimed at Android Version 1.6 (Donut, API 4) and later.
- android-support-v13.jar – Version 13 is for apps aimed at Android 3.2 ( API 13) and later.
The recent Android Development Tools (ADT) Eclipse plug-in automatically adds the Version 4 Support Library when a new project is started. To change to the later library when targeting only newer devices use the Java Build Path option from the projects Properties (select the project in the Eclipse Package Explorer and use the File menu to bring up Properties). Use the Libraries tab to remove and add JARs.
The release of Ice Cream Sandwich (Android 4.0, API 14) made available a new layout, the GridLayout is designed to help with precision when designing screens. There has been a GridView since the first Android release, which is useful to display a grid of repeating data in repeating Views of the same type. A GridLayout can contain assorted Views in its cells to support complex layouts with more precision and more efficiency than nesting many LinearLayouts.
To aid backwards compatibility the GridLayout is available in a JAR file for devices running Android 2.1 (API 7) and later. The android-support-v7-gridlayout.jar is in the folder android-sdk/extras/android/compatibility/v7/gridlayout/libs under the Android SDKs install location.
Load the Support Library Samples Into an Eclipse Project
There are three samples in the android-sdk/extras/android/compatibility/samples folder:
- Support4Demos – Accessibility Delegate and Manager, Content (Local Service Broadcaster), Fragment (Alert Dialog, Arguments, Context Menu, Custom Animation, Dialog, Dialog or Activity, Hide and Show, Layout, List Array, Menu, Nesting Tabs, Pager, Receive Result, Retain Instance, Stack, State Pager, Tabs, Tabs and Pager), Loader (Cursor, Custom, Retained, Throttle), Share Compatibility
- Support13Demos – Fragment (Action Bar Tabs Pager, Nesting Pager, Nesting State Pager, Pager, State Pager)
- SupportAppNavigation – Simple Up Navigation, Peer Activities, View from other task, Content Category, Notifications (direct and interstitial)
There is no sample for using the GridLayout compatibility JAR but in the android-sdk/extras/android/compatibility/v7/gridlayout folder there is a read me and values XML files to instruct on using the support GridLayout JAR.
To load a Support Library example demo app an empty project is created in Eclipse and the source code is imported from the samples directory.
Load and Run the Android Support Library v4 Demo
Start a new project and in the first dialog enter values as for this screen:
Click Next and uncheck the options Create custom launcher icon and Create activity, then click Finish. The empty Support4Demos project is created in the workspace. With the project highlighted use the File menu and select Import. In the Import dialog expand the General folder and select File System and then click Next. Use the Browse button to select the android-sdk/extras/android/compatibility/samples/Support4Demos folder under the Android SDK install location. Expand the Support4Demos folder and check the res and src folders, also check the AndroidManifest.xml file.
Click Finish and then run the demo.
Load and Run the Android Support Library v13 Demo
Start a new project and in the first dialog enter values as for this screen:
Continue as for loading the v4 demo as above (but using the Support13Demos folder). From the projects Properties (select the project in the Eclipse Package Explorer and use the File menu to bring up Properties). Use the Java Build Path option, under the Libraries tab, to remove the android-support-v4.jar library and add the android-support-v13.jar via the Add External JARs button. Use the Order and Export tab and check android-support-v13.jar so that it's code is included in the built Android Package (APK) install file. Run the demo.
Load and Run the Support Library App Navigation Demo
Start a new project and in the first dialog enter values as for this screen:
Continue as for loading the v4 demo as above (using the SupportAppNavigation folder). Run the demo.
Additional Information
See also the Support Library online developer pages:
For a full list of all the articles in Tek Eye see the full site Index.
Archived Comments
Roy on February 3, 2013 at 2:32 pm said: Thanks for posting this. Too bad your page doesn’t show higher in Google’s search.
SBossen on September 4, 2013 at 11:20 pm said: Thanks for the well written article. It took a while searching to find this information. I’ve also added steps on my site for how Load and Run the Android Support Library v7 Demo which has some extra steps.
http://right-handed-monkey.blogspot.com/2013/09/how-to-run-android-support-library.html
Author:Daniel S. Fowler Published: Archived: