Search code examples
androidandroid-recyclerviewandroid-support-libraryandroid-support-design

What is the difference between two RecyclerView dependencies?


I am using the following RecyclerView:

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

which has the following dependency in the build.gradle:

implementation 'androidx.recyclerview:recyclerview:1.0.0'

which is downloaded after clicking the download button in front of the RecyclerView in Design mode of android studio. I run my application on Oreo and it works perfectly.

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.

Now i did a bit research and found that i have to use the:

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

and following xml tag:

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

Now my question is that what is the difference between the

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

and

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

Which one is created for which purpose and which one should be used in which situation? Why android studio download the one that is not supported on KitKat instead of downloading the one that is supported on almost previous version of android? Thanks!!!


Solution

  • What is the difference between two RecyclerView dependencies?

    The RecyclerView Support Library and RecyclerView AndroidX library are having the same purpose. The main difference is the package name. The AndroidX mainly a repackage and re-branded support library with the main purpose to ease the Android development process. All the support library capabilities is still existed in AndroidX, but the newest capabilities and development shifted to AndroidX now. But it doesn't mean the Support library is deprecated. See the following note from Support Library documentation :

    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.

    So, you should migrate to AndroidX for your recent project.


    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.

    This probably a bug in your code or the least probability is a bug inside the AndroidX RecyclerView. We can't find the problem without your error log. So, you need to provide the error log in your question.


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

    For new project, you should migrate to AndroidX. But for your legacy project that tightly depends on libraries that need a support library as dependency, you need to do one of the following:

    1. upgrade the libraries to AndroidX (which is tedious and probably not worth the effort)
    2. keep using the Support library.
    3. Use android.enableJetifier in your gradle.properties, see Migrating to AndroidX