23
build.gradle(app)

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.example.todolistapp"
        minSdkVersion 16
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    // Room
    def room_version = "2.0.0"
    implementation "androidx.room:room-runtime:$room_version"
    kapt "androidx.room:room-compiler:$room_version"

    // ViewModel and LiveData
    def lifecycle_version = "2.0.0"
    implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
    kapt "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"

    // For Floating Action Button
    implementation 'com.google.android.material:material:1.0.0'
}

as you can see from my dependencies, I did not import the recycled view Androidx library.

androidx.recyclerview:recyclerview:1.0.0

but as shown below, I can comfortably use it in my layout (activity_main.xml) and MainActivity code.

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewTasks"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipToPadding="false"
        android:paddingBottom="80dp"/>

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="16dp"
        android:tint="@android:color/white"
        app:srcCompat="@android:drawable/ic_input_add"/>
</FrameLayout>

MainActivity.kt

import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity(), TaskAdapter.TaskViewCliskListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        recyclerViewTasks.layoutManager = LinearLayoutManager(this)
}

What is responsible for this behavior?

peterh
  • 11,875
  • 18
  • 85
  • 108
EdgeDev
  • 2,376
  • 2
  • 20
  • 37

6 Answers6

30

As per the dependencies of the com.google.android.material:material:1.0.0:

androidx.recyclerview:recyclerview:1.0.0

This means that the Material library takes a transitive dependency on RecyclerView already and you don't need to manually include it yourself.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • 1
    Not unless some newer version of RecyclerView and you want to manually include that newer version. That's not the case right now though, so there's no need to explicitly add it right now. – ianhanniballake Jan 22 '19 at 05:22
9

I did not Import the Recycler View AndroidX Library, yet i am using. Why and How is it working?

Because you have added the dependencies of com.google.android.material:material:1.0.0

No need to add androidx.recyclerview:recyclerview:1.0.0 if youhave already added com.google.android.material:material:1.0.0

AskNilesh
  • 67,701
  • 16
  • 123
  • 163
5

com.google.android.material:material:1.0.0 Includes The RecyclerView Component So you dont need to add it externally.

if you added com.google.android.material:material:1.0.0to your app dependencies you don't need to add androidx.recyclerview:recyclerview:1.0.0 to your dependencies because it already included in material library.

For Additional Information https://developer.android.com/jetpack/androidx/migrate/class-mappings

Joker
  • 153
  • 14
Ashvin solanki
  • 4,802
  • 3
  • 25
  • 65
4

In case your question is about using a different version than the one in the material dependencies.

I was trying to use alpha version of recyclerview every time I add the androidx.recyclerview:recyclerview dependency manually the code works fine on build time. But the App keeps crashing because it can't find the new classes I use from the alpha version of the recyclerview on runtime.

I tried to use the latest alpha version of material dependency but it also depends on the latest stable version on recyclerview .. so it didn't help.

To solve it I excluded the recyclerview decency from material and added the recyclerview decency myself like this.

implementation("com.google.android.material:material:1.1.0") {
    exclude(group = "androidx.recyclerview", module = "recyclerview")
}
implementation("androidx.recyclerview:recyclerview:1.2.0-alpha04")
Ahmad Melegy
  • 1,530
  • 1
  • 16
  • 18
  • 1
    [An updated version](https://gist.github.com/lmj0011/229959d56c99efb067f494e78358228a) of this answer since the queue is full. – lasec0203 Dec 03 '20 at 06:43
  • Didn't know this was possible. Thanks for sharing that! I'll keep it in mind. – M.Ed Jan 05 '22 at 13:33
1

I have tried and tested.The com.google.android.material:material:1.0.0 includes RecyclerView too. Might be it is here to give material design look n feel same like as MaterialButton

Zaid Mirza
  • 3,540
  • 2
  • 24
  • 40
0
dependencies{

implementation 'com.google.android.material:material:1.0.0'

}

or

dependencies{

implementation 'com.android.support:design:your version'

}

if you already added

com.google.android.material:material:1.0.0 or com.android.support:design:version

in the previous version of android recyclerview into design library but in the version of Androidx its on material library.

in your dependencies then recyclerview dependencies is not needed. its already added in material/design library

Check Here

for Details Android Library

  • This doesn't answer the question. – Zun Jun 25 '19 at 09:59
  • 2
    why this doesn't the answer . i provide the answer how work androidx Recyclerview dependencies. what the wrong i do here? What you want to know actually? you can ask me. i can help you. – Kamrujjaman Joy Jun 26 '19 at 03:50
  • Try and read. The question is `I did not Import the Recycler View AndroidX Library, yet, i am using it. Why and How is it working?`. So you tell me, are you answering the question? Also, yes I can see that you edited the answer https://stackoverflow.com/revisions/56700924/3 – Zun Jun 26 '19 at 11:34