Do we still need support-v4 and appcompat-v7 when we have support-design?

953 views Asked by At

There is a lot of discussion about this. Some say if I have appcompat-v7 I do not need support-v4 since appcompat-v7 already has all the classes of support-v4. Also, that support-design already has all the classes from appcompat-v7 hence we do not even need that. There are some answer that are many years old so things might have changed by now. I did a test, in my project I have support-design, support-v4 and appcompatv7, after removing support-v4 and appcompatv7 I am still able to use all the classes from support-v4 and appcompatv7 by just having support-design. Can anyone clarify this?

All I am trying to do is remove support-v4 from my project and only including the indpendent modules from support-v4 such as support-compat, support-coreui, etc. However, if support-design adds support-v4 automatically this doesn't seem possible. I have removed support-v4 from gradle and appcompat-v7 and all the classes from support-v4 are still found in my project by just keeping support-design.

1

There are 1 answers

19
Eugen Pechanec On

Do we still need support-v4 and appcompat-v7 when we have support-design?

Technically, it depends on your point of view.

You don't need to specify them in your dependencies but design still needs all those classes at compile time and runtime. Gradle + maven take care of automatically fetching these transitive dependencies.

Here's the dependency graph of a recent version of design support library:

  • design
    • support-v4
      • support-compat
        • support-annotations
        • android.arch.lifecycle:runtime
          • android.arch.lifecycle:common
          • android.arch.core:common
          • support-annotations
      • support-media-compat
        • support-annotations (*)
        • support-compat (*)
      • support-core-utils
        • support-annotations (*)
        • support-compat (*)
      • support-core-ui
        • support-annotations (*)
        • support-compat (*)
      • support-fragment
        • support-annotations (*)
        • support-compat (*)
        • support-core-ui (*)
        • support-core-utils (*)
    • appcompat-v7
      • support-annotations (*)
      • support-core-utils (*)
      • support-fragment (*)
      • support-vector-drawable
        • support-annotations (*)
        • support-compat (*)
      • animated-vector-drawable
        • support-vector-drawable (*)
        • support-core-ui (*)
    • recyclerview-v7
      • support-annotations (*)
      • support-compat (*)
      • support-core-ui (*)
    • transition
      • support-annotations (*)
      • support-compat (*)

(*) denotes a dependency already mentioned before.

However, if support-design adds support-v4 automatically this doesn't seem possible.

While researching the above tree I can, to my own surprise, confirm this.

For now you can try explicitly removing support-v4 from design dependencies and see where that leads you (i.e. you may crash because of missing classes).

implementation ('com.android.support:design:27.0.2') {
    exclude group: 'com.android.support', module: 'support-v4'
}

If you do crash import the missing libraries until you don't.

Apparently the Android Team has fixed this and will ship in the next support library.