> 文档中心 > (六)Android Gradle - 依赖管理之依赖查询

(六)Android Gradle - 依赖管理之依赖查询


前言

项目中,有时候难免碰到依赖管理的问题。这时候学会依赖查询的重要性就凸显出来了,可以快速的帮助我们找出问题。下面将介绍如何查询项目中的依赖。

使用方法

查询Release版本的依赖树命令:

gradlew app:dependencies --configuration releaseRuntimeClasspath

注意:由于在我们的App项目里没有Release版本,因为在配置里配置了

productFlavors {    dev {    }    yzwill {    }}

于是,我们的版本就变成了,devDebug,devRelease,yzwillDebug,yzwillRelease。如果你没有上面的配置,那么默认就是dubug和release。

于是我们需要修改下命令,如下:
gradlew app:dependencies --configuration yzwillReleaseRuntimeClasspath

运行结果如下图所示:
在这里插入图片描述

接下来我们看下每一条代码代表的意思:

1.x.x.x 添加该依赖
+--- androidx.appcompat:appcompat:1.2.0|    +--- androidx.annotation:annotation:1.1.0
2.x.x.x(*) 该依赖已经有了,将不再重复依赖

例如在lib_animation模块中,由于appcompat在项目初始就被添加进来,所以后面的将不再重复依赖

+--- project :lib_animation|    +--- androidx.appcompat:appcompat:1.2.0 (*)
3.x.x.x -> x.x.x(*) 该依赖的版本被箭头所指的版本代替,并且该依赖已经有了,不再重复依赖

表示这条依赖是无效的 别的地方已经有了!!
依旧是在lib_animation模块中,在lottie第三方资源中,引用了appcompat。

 \--- com.airbnb.android:lottie:3.5.0|  +--- androidx.appcompat:appcompat:1.0.0 -> 1.2.0 (*)
4.x.x.x -> x.x.x 该依赖的版本被箭头所指的版本代替,会在项目里选择版本最高的

依旧是在lib_animation模块中,在leakcanary第三方资源中,引用了annotation,会自动的将版本提升至项目里版本最高的(这是在没有强制指定版本的情况下)。

 com.squareup.leakcanary:leakcanary-android-no-op:1.6.3|    \--- androidx.annotation:annotation:1.0.0 -> 1.1.0