为什么 Android Studio 外部库显示多个版本依赖关系?

Cod*_*ien 6 android gradle android-studio

在此输入图像描述

即使我明确添加了一个实现

implementation 'androidx.activity:activity:1.5.1'
Run Code Online (Sandbox Code Playgroud)

并运行./gradlew :app:dependencies检查树,发现所有版本都被新版本替换。Android Studio 仍然显示存在其中三个。

androidx.activity:activity:1.2.4 -> 1.5.1 (*)
Run Code Online (Sandbox Code Playgroud)

Top*_*ter 0

它显示多个版本来通知我们如果删除其中一个依赖项会发生什么。

例如,在 OP 的情况下,如果我们删除所有:

implementation 'androidx.activity:activity:1.5.1'
Run Code Online (Sandbox Code Playgroud)

然后1.2.4将被使用(因为某个地方的某些东西取决于该版本)。

当然,1.2.4只有在依赖项没有任何+号时才会使用,例如:

implementation 'androidx.activity:activity:1.2.4+'
Run Code Online (Sandbox Code Playgroud)