方式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
如果你嫌命令行麻烦还有鼠标操作的方式
鼠标双击即可运行
其实方式一的命令行执行的就是截图里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同意将会出现一个网页地址登录该网址。
该网页还提供冲突提示列出了引用了此类库的类库效果如下
小结
方式1和方式2实际上是同一种方法方式3借助了Gradle官网为我们提供了视觉上更友好的查看包依赖。当编译出现包依赖冲突的问题时使用这种方式能极大的提高我们快速定位问题来源的效率。
参考资料Getting started with build scansscans.gradle.com