How can I determine which dependency is determining other library's version?

Viewed 137

I have the following dependencies in an Android project:

dependencies {
        implementation "androidx.appcompat:appcompat:1.3.0-alpha02"
        implementation 'androidx.core:core-ktx:1.3.2'
        implementation "androidx.fragment:fragment-ktx:1.2.5"
        implementation "androidx.preference:preference:1.1.1"
        implementation 'com.squareup.picasso:picasso:2.5.2'
        implementation 'com.android.billingclient:billing:3.0.1'
        implementation 'androidx.multidex:multidex:2.0.1'
        api 'com.google.android.material:material:1.3.0-alpha03'
        implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_coroutines_version"
        implementation 'com.jakewharton.timber:timber:4.7.1'
        implementation platform('com.google.firebase:firebase-bom:26.1.0')
        implementation 'com.google.firebase:firebase-ads'
}

I would expect core-ktx:1.3.2 to bring in androidx.core:core:1.3.2, but in the project pane, I can see that the actual dependency that has been brought in is androidx.core:core:1.5.0-alpha02. This is evidenced by the fact that I have access to newer APIs like WindowInsetsCompat.getInsets(), which didn't yet exist in 1.3.2.

I want to figure out why this different version of the library has been brought in. I assume one of my other dependencies is using 1.5.0-alpha02, but how can I tell which one without reading every POM file (and dependent POM files up the dependency chain)?

1 Answers

I recommend trying the Gradle dependencyInsight task.

Every Gradle project provides the task dependencyInsight to render the so-called dependency insight report from the command line. Given a dependency in the dependency graph you can identify the selection reason and track down the origin of the dependency selection.


I created a new project and pasted your dependencies in. Then I ran:

./gradlew app:dependencyInsight --configuration debugRuntimeClasspath --dependency "androidx.core:core"

This output a report that began with:

androidx.core:core:1.5.0-alpha02
\--- androidx.appcompat:appcompat:1.3.0-alpha02
     +--- debugRuntimeClasspath

So it seems that androidx.appcompat:appcompat:1.3.0-alpha02 depends on androidx.core:core:1.5.0-alpha02.

The report also says:

androidx.core:core:1.3.2 -> 1.5.0-alpha02
\--- androidx.core:core-ktx:1.3.2
     +--- debugRuntimeClasspath

So you are correct that androidx.core:core-ktx:1.3.2 brings in version 1.3.2... it just happens to be overridden by appcompat's dependency.

Related