3

I'm working on an app which uses the RecyclerView component. I was checking my build.gradle file and it had these dependencies:

compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.3.1'

There was no 'com.android.support:recyclerview-v7:25.3.1', and yet I had a RecyclerView (android.support.v7.widget.RecyclerView) in the project.

Which of the packages above also contains the RecyclerView? Or is there something I don't understand about the support library packages?

bernardo.g
  • 826
  • 1
  • 12
  • 27
  • You can find that in google very easily. Otherwise add it to the view using the design view in Android Strudio which adds the library for you. – Juan Oct 08 '17 at 17:30
  • I have reasons to believe it's this one compile 'com.android.support:appcompat-v7:25.3.1' for more information visit https://developer.android.com/training/material/lists-cards.html – Ankit Arora Oct 08 '17 at 17:34
  • check out https://developer.android.com/topic/libraries/support-library/packages.html for the full list of support libs – Viktor Yakunin Oct 08 '17 at 17:37

2 Answers2

4

Which of the packages above also contains the RecyclerView?

None of them. RecyclerView is in recyclerview-v7.

Or is there something I don't understand about the support library packages?

design has a transitive dependency upon recyclerview-v7. Hence, by depending upon design, your app also depends upon recyclerview-v7. This is handled for you automatically.

You could simplify your dependencies further, as design depends upon appcompat-v7, so you do not need to request appcompat-v7 yourself:

// compile 'com.android.support:appcompat-v7:25.3.1'
compile 'com.android.support:cardview-v7:25.3.1'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
compile 'com.android.support:design:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:support-v4:25.3.1'

Then, comment out the support-v4 dependency and see if you have build problems. Most likely, what you are using from there is pulled in by something else already, and so you will not need that dependency in your build.gradle file either.

You can read more about transitive dependencies here.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I see. `design` doesn't **contain** the code for `RecyclerView` but it depends upon the package that does. I commented out `appcompat` and `support-v4` and it compiled without erros. Thanks for the explanation. – bernardo.g Oct 08 '17 at 23:40
-1

just add it in your app gradle

compile "com.android.support:recyclerview-v7:25.3.1

Ankit Aman
  • 999
  • 6
  • 15