
I use androidx.appcompat:appcompat:1.4.1 in my android project
and androidx.appcompat:appcompat:1.4.1 dependent androidx.activity:activity:1.2.4
and androidx.activity:activity:1.2.4 dependent both androidx.lifecycle:lifecycle-common:2.0.0 and androidx.lifecycle:lifecycle-common:2.4.1
how can i config my build.gradle, and let the gradle only use one version androidx.lifecycle:lifecycle-common, thank you
Gradle’s version conflict resolution is already doing what you want. When you see 1.2.3 -> 4.5.6
in the dependency report, that means the requested version was 1.2.3
, but 4.5.6
was selected.
So in your example, lifecycle-common
version 2.0.0
was requested, but version 2.4.1
was selected.
Hi, Chris Dore. thanks for your reply.
In fact, when i apply appcompat sdk, i use the gradle code below:
api "androidx.appcompat:appcompat:$APPCOMPAT_VERSION", { exclude group: 'androidx.lifecycle', module: 'lifecycle-common' }
but still print like the picture above, appcompat still dependent lifecycle-common even i exclude it.
I want gradle don’t print lifecycle-common sdk, what should i do?
should i exclude savedstate or lifecycle-viewmodel-savedstate instead of lifecycle-common to achieve this?
Why do you want this? Is there a problem with Gradle choosing version 2.4.1 of lifecycle-common?
without exclude, gradle download multiple versions of lifecycle-common, both 2.0.0 and 2.4.1, i think this will increase the compile time of my project. 
Gradle is only using one version for the compile classpath, version 2.4.1. That’s what 2.0.0 -> 2.4.1
means in the dependencies report. If you are actually seeing multiple versions on the compile classpath then something weird is going on.
A task like the following will show you the resolved jars for the compile classpath:
task dumpCompileDeps {
doLast {
println configurations.compileClasspath.join('\n')
// or filtered
//println configurations.compileClasspath.findAll { it.name ==~ /lifecycle-common.*/ }.join('\n')
}
}
fine, Chris Dore, thanks a lot !