Androidx dependencies

from the CommonsWare Community archives

At November 17, 2019, 5:38am, Hadysalhab asked:

Hi,
Every modern android project using android studio, will have the following dependencies added by default:

Also, using specific classes requires adding their corresponding dependencies (like recyclerview for example)

My Question is : how are we able to use directly the class that comes from the androidx.fragment , without adding the necessary dependency:
implementation "androidx.fragment:fragment:$fragment_version"
Thanks


At November 19, 2019, 11:45am, mmurphy replied:

I apologize for my delay in responding — I was out of the office for a few days.

If your app is depending directly upon androidx.appcompat:appcompat, then you are pulling in many other libraries as transitive dependencies. Basically, androidx.appcompat:appcompat declares that it depends on other libraries, so Gradle will add those to your project automatically.

In my AndroidX Tech site, you can find out the transitive dependencies for a given library, such as androidx.appcompat:appcompat:1.1.0:

https://androidx.tech/artifacts/appcompat/appcompat/1.1.0/

There, you will see that it depends upon androidx.fragment:fragment:1.1.0, among other libraries. Gradle handles these transitive dependencies for you, making their contents available in your app automatically.