Android中的支持库程序包是一组代码库,其主要目的是为代码和Android API框架提供向后兼容性。在现实世界中,很可能将在最新版本的Android上开发的应用程序用于较旧版本的Android OS。因此,在开发android应用程序时应遵循的最佳做法是在项目文件中包含支持库。此外,对于仅通过库API提供的功能,也需要这些库。
Android支持库(com.android.support)
这些库程序包由Google提供,以向后兼容android应用程序。这些软件包的名称以库支持的最低版本的Android API结尾。例如,程序包名称support-v4和support-v7表示最低支持的Android API版本分别为4和7。但是,库函数和模块的不断发展导致最低支持的Android API级别版本更改为级别14(Android 4.0),以及2017年7月发布的支持库版本26.0.0 。
AndroidX包库(androidx。*)
与2018年发布的Android Jetpack一起引入的AndroidX是一种组织支持库的全新方式。较旧的支持库对开发人员有些混乱,因为仅通过查看其名称就无法说出所有类都包含在特定的库中。为了解决此问题,Google随Android 9.0(API级别28)的发布推出了AndroidX(代表Android EX张力)库。从androidx开头的任何库名称。自动成为Jetpack的一部分。它包括现有的android支持库以及最新的Jetpack组件。此外,由于Jetpack知道要使用什么代码,因此开发人员无需理会库的版本。
差异表
Android Support Libraries |
AndroidX Package Libraries |
---|---|
Syntax of writing dependency: com.android.support:recyclerview-v7 | Syntax of writing dependency: androidx.recyclerview:recyclerview |
While using support libraries in the project, it is mandatory to keep the same version for all the support libraries. | Developers are free to use a different version of dependency for different android components. |
Dependencies that are required to add in order to use an android component in the application include various other things that are of no use. | Developers are allowed to add only those dependencies which they are going to use in the application. |
Tha package of support library is bundled with the Android operating system. For eg: android.content.Intent | Unbundled libraries are moved to androidx.* namespace and are packed with application’s APK. For eg: androidx.fragment.app.Fragment |
The package name contains the minimum supported API level. | The package has no dependency on the API level. |
All dependencies are required to update before using because all the support libraries need to have the exact same version specification. | AndroidX libraries can be updated individually. Thus, developers can update only those libraries which are needed in the project. |
The support of com.android.support libraries have been stopped by Google. | It is the recommended library package by Google to use in the project. |
Note:
With the release of Android API level 28 i.e, Android 9.0, Google has stopped the support for com.android.support libraries and advised the developers to use AndroidX libraries which are a part of Jetpack for all new projects. To know what is the new mapping of support libraries in AndroidX, click here.
Google also provide the feature to migrate an existing project in order to use the AndroidX libraries. Visit this link to read the official Google documentation.