Learn about Android Support Library

Tram Ho

Note: With the release of Android 9 (API 28), a new version of Support Library appears, which is AndroidX – a part of Jetpack . The AndroidX library includes the Support Library and new components of Jetpack.

You can still use the Support Library, or switch to AndroidX. Older versions (added from API version 27 and earlier, and packaged in android.support. *) Will still be available on Google Maven. However, all new libraries will be added to AndroidX.

AndroidX is highly recommended when starting a new project, or if you want to migrate your existing application to use AndroidX.

But AndroidX library still contains Support Library in essence. Let’s find out what it is and what it does.


What is Support Library

When creating an application that supports multiple API versions, you may want a standard way to use the features of the new API on older API versions. Instead of writing code to handle low APIs, you can use those compatibility features with the support library. In addition, it provides utility classes and features not available in standard APIs for easy development and support on more devices.

Note: Starting from Support Library version 26.0.0, the minimum API level supported on most devices has been increased to API 14 (Android 4.0), for more information you can read Version Support and Package Names .

In a nutshell, Support Library is a library package that can be added to Android apps in order to make it possible for devices with low Android versions to use APIs designed for a higher version, in addition to providing Application development utility.

Use the Support Library

There are many ways to use the Support Library, compatibility for APIs on older versions is just one of them. Here is all:

  • Backward compatibility: libraries provide backward compatibility for the API. For example, support Fragment supports devices under Android 3 (API 11).
  • Help and utility classes: provide utility classes, purpose for user interface development.
  • Debug and utility: provide utilities for writing code such as annotations used in Lint or multidex support

For example: support-v4, support-appcompat-v7

  • support-v4: includes large API package, includes support for components:
    • Application Components: Activity, Fragment
    • UI Components
    • Accessible ability
    • Data processing
    • Internet connection….
  • v7 libraries: These libraries provide specific feature sets and can be implemented in your application independently of each other.

Use the Support API or Framework

The Support Library provides many classes and methods similar to the APIs available for the Android Framework. When you know this, you will probably wonder whether to use existing APIs or APIs from Support Library. Here are instructions when you should use the API from the Support Library instead of the API from the Framework:

  • Compatibility for a specific feature: If you want to use newly developed features for devices running old APIs, you must use classes and methods from the Support Library
  • Compatibility for related library features: Once you have used the classes in the Support Library, those classes may depend on one or more other classes in the Support Library. You should use the Support Library classes for those dependencies.

    For example, if you used ViewPager from the Support Library then you should use the FragmentPagerAdapter or FragmentStatePagerAdapter.

  • Device compatibility: If you do not have any specific features in the application that need backward compatibility, you should still use the classes in the Support Library.

    For example, you should use AppCompatActivity instead of Activity, so you can use newer features later, such as the new Permission related feature from Android 6.0.

The Support Library classes that provide platform-compatible deployment of API classes may not be able to provide the full set of functionality available in the latest release, due to platform version limitations. For this reason, you should review the references for the library classes and methods you use and test them thoroughly on devices running the latest version of the platform supported by your application.

Version Support and Package Names

Some Support Library packages have a package name that indicates the minimum API level they initially supported, using the v # notation, such as support-v4. Starting with Support Library version 26.0.0 (released in July 2017), the minimum supported API level has changed to Android 4.0 (API 14) for all Support Library packages. For this reason, when working with any recent release of the Support Library, you should not assume that the v # package symbol indicates the minimum API support level. This change in recent releases also means that library packages with v4 and v7 are essentially equivalent at the minimum API level they support. For example, the support package-v4 and support package-v7 both support a minimum API level of 14, for Library Release releases of 26.0.0 or higher.

Support Library release version

The release version of Support Library, such as 24.2.0 or 25.0.1, differs from the minimum API level supported by any library in that release. The version number of the release shows which platform API version is built and therefore, the most recent APIs may be included in this library version. Specifically, the first part of the release version number, for example 24 in version 24.2.0, usually corresponds to the platform API version available at release. The release version of the support library says it incorporates some features of that API level, but you should not assume that it provides compatibility with all features released in the background API version. new platform.

Library dependent

Most libraries in the Android Support Library have some dependencies on one or more libraries. For example, nearly all Support Library depend on the support compat package. In general, you don’t need to worry about support library dependencies, because the class builder tool manages library dependencies for you, by automatically including dependency libraries. If you want to see which libraries and library dependencies are included in your application, run the following command at the root of your application development project to get reports of dependencies for that project. , including Android Support Library and other libraries:

For more information about adding Support Library to your development project using Gradle, see Setting Up Support Library . For more information on how to work with Gradle, see Configure your application . Note that all Android Support Library also depends on some platform level of the platform, for recent releases, it is Android 4.0 (API level 14) and above.


Article translated from: Support Library (thankyou)

Share the news now

Source : Viblo