两个 RecyclerView 依赖项有什么区别?

What is the difference between two RecyclerView dependencies?

我正在使用以下 RecyclerView:

<androidx.recyclerview.widget.RecyclerView ... />

build.gradle 中有以下依赖:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

在android工作室的Design模式下点击RecyclerView前面的下载按钮后下载。 我 运行 我在 Oreo 上的应用程序,它运行良好。

但是当我运行应用在KitKat时,应用被杀死,所以我注释掉了RecyclerView及其相关的源代码和运行应用再次在 KitKat 上正确应用 运行s,所以我意识到问题出在 KitKat 版本的 RecyclerView 上。

现在我做了一些研究,发现我必须使用:

implementation 'com.android.support:recyclerview-v7:28.0.0'

和以下 xml 标签:

<android.support.v7.widget.RecyclerView ... />

现在我的问题是

<androidx.recyclerview.widget.RecyclerView ... />
implementation 'androidx.recyclerview:recyclerview:1.0.0'

<android.support.v7.widget.RecyclerView ... />
implementation 'com.android.support:recyclerview-v7:28.0.0'

创建哪一个是为了什么目的,应该在什么情况下使用哪一个?为什么 android studio 下载 KitKat 不支持的那个,而不是下载 android 几乎以前版本支持的那个?谢谢!!!

What is the difference between two RecyclerView dependencies?

RecyclerView支持库RecyclerViewAndroidX库具有相同的目的。主要区别在于包名。 AndroidX 主要是一个重新打包和重新标记的支持库,主要目的是简化 Android 开发过程。 AndroidX 中仍然存在所有支持库功能,但现在最新的功能和开发转移到了 AndroidX。但这并不意味着支持库已被弃用。请参阅 Support Library 文档中的以下说明 :

Note: With the release of Android 9.0 (API level 28) there is a new version of the support library called AndroidX which is part of Jetpack. The AndroidX library contains the existing support library and also includes the latest Jetpack components.

You can continue to use the support library. Historical artifacts (those versioned 27 and earlier, and packaged as android.support.*) will remain available on Google Maven. However, all new library development will occur in the AndroidX library.

We recommend using the AndroidX libraries in all new projects. You should also consider migrating existing projects to AndroidX as well.

因此,您应该为最近的项目迁移到 AndroidX。


But when i run the app on KitKat, the application is killed, so I comment out the RecyclerView and its related source code and run the application again and this time application runs properly on KitKat, so i realize that the problem is with the RecyclerView for the KitKat version.

这可能是您代码中的错误,或者最不可能是 AndroidX RecyclerView 中的错误。没有您的错误日志,我们无法找到问题所在。因此,您需要在问题中提供错误日志。


Which one is created for which purpose and which one should be used in which situation?

对于新项目,您应该迁移到 AndroidX。但是对于您的遗留项目,它紧密依赖于需要支持库作为依赖的库,您需要执行以下操作之一:

  1. 将库升级到 AndroidX(这很乏味,可能不值得努力)
  2. 继续使用支持库。
  3. 在您的 gradle.properties 中使用 android.enableJetifier,参见 Migrating to AndroidX