快速查看Gradle项目包依赖情况

Gradle项目中,导入依赖包和并对其管理是开发人员绕不开的事情,在导入的过程中,一不小心就会遇到新导入的依赖库和原有的类库冲突的问题,我在之前的一篇文章遇到异常Multiple dex files define时里提供了解决方法。本文对如何定位依赖冲突这个环节提供更多的方法

方式1

./gradlew 模块名:dependencies

这个命令会打印出该模块下的所有第三方类库的依赖情况,有多种展示情况,complie编译时的,Runtime运行时(打到APK包时)的,debug下,release下。

如下展示的是debugCompileClasspath即debug编译时的引包情况:

debugCompileClasspath - Resolved configuration for compilation for variant: debug
+--- org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.31
|    \--- org.jetbrains.kotlin:kotlin-stdlib:1.2.31
|         \--- org.jetbrains:annotations:13.0
+--- com.android.support:appcompat-v7:27.1.1
|    +--- com.android.support:support-annotations:27.1.1
|    +--- com.android.support:support-core-utils:27.1.1
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    \--- com.android.support:support-compat:27.1.1
|    |         +--- com.android.support:support-annotations:27.1.1
|    |         \--- android.arch.lifecycle:runtime:1.1.0
|    |              +--- android.arch.lifecycle:common:1.1.0
|    |              \--- android.arch.core:common:1.1.0
|    +--- com.android.support:support-fragment:27.1.1
|    |    +--- com.android.support:support-compat:27.1.1 (*)
|    |    +--- com.android.support:support-core-ui:27.1.1
|    |    |    +--- com.android.support:support-annotations:27.1.1
|    |    |    +--- com.android.support:support-compat:27.1.1 (*)
|    |    |    \--- com.android.support:support-core-utils:27.1.1 (*)
|    |    +--- com.android.support:support-core-utils:27.1.1 (*)
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    +--- android.arch.lifecycle:livedata-core:1.1.0
|    |    |    +--- android.arch.lifecycle:common:1.1.0
|    |    |    +--- android.arch.core:common:1.1.0
|    |    |    \--- android.arch.core:runtime:1.1.0
|    |    |         \--- android.arch.core:common:1.1.0
|    |    \--- android.arch.lifecycle:viewmodel:1.1.0
|    +--- com.android.support:support-vector-drawable:27.1.1
|    |    +--- com.android.support:support-annotations:27.1.1
|    |    \--- com.android.support:support-compat:27.1.1 (*)
|    \--- com.android.support:animated-vector-drawable:27.1.1
|         +--- com.android.support:support-vector-drawable:27.1.1 (*)
|         \--- com.android.support:support-core-ui:27.1.1 (*)
\--- com.android.support.constraint:constraint-layout:1.0.2
     \--- com.android.support.constraint:constraint-layout-solver:1.0.2

分层展示,不仅展示了该模块下每个类库的名称、版本号,还展示了各类库里所需依赖的类库。

方式2

如果你嫌命令行麻烦,还有鼠标操作的方式

方式2

鼠标双击即可运行

其实方式一的命令行执行的就是截图里dependencies任务。

Gradle项目构建的过程就是依次执行完所有任务的过程。

方式3

如果你嫌在命令行窗口展示观看不友好,这里还有一种体验更好的方式。

输入下面命令行:

./gradlew build --scan

出现如下:

Publishing a build scan to scans.gradle.com requires accepting the Terms of Service defined at https://scans.gradle.com/terms-of-service. Do you accept these terms? [yes, no]

输入yes同意,将会出现一个网页地址,登录该网址。

方式3

该网页还提供冲突提示,列出了引用了此类库的类库,效果如下

冲突细节信息

小结

方式1和方式2实际上是同一种方法,方式3借助了Gradle官网为我们提供了视觉上更友好的查看包依赖。当编译出现包依赖冲突的问题时,使用这种方式能极大的提高我们快速定位问题来源的效率。

参考资料

Get started with build scans

猜你喜欢

转载自blog.csdn.net/sugaryaruan/article/details/79905339