【Android Gradle 插件】Gradle 依赖管理 ⑥ ( dependencies 依赖查找路径 | dependencies 依赖冲突 | dependencies 依赖库层级分析 )

Android Plugin DSL Reference 参考文档 :





一、dependencies 依赖查找路径



Android 工程中 , 配置的 依赖 , 有 2 2 2 种查找依赖包的方式 ,

  • 方式一 : 到根目录中配置的 google , mavenCentral , jcenter 远程仓库中查找依赖库 ;
allprojects {
    
    
    repositories {
    
    
        google()
        mavenCentral()
        jcenter() // Warning: this repository is going to shut down soon
    }
}
  • 方式二 :SDK 目录中的本地仓库查找 , 其路径是 SDK\extras\android\m2repository , 如下图 :

在这里插入图片描述
在我的电脑的 SDK\extras\android\m2repository\com\android\support 路径中 , 就是依赖中常用的支持库 :

在这里插入图片描述





二、dependencies 依赖冲突问题



添加构建依赖项 参考文档 : https://developer.android.google.cn/studio/build/dependencies


如果在 build.gradle 的 dependencies 依赖配置中 , 配置如下依赖库 :

dependencies {
    
    
	implementation 'com.facebook.fresco:fresco:0.14.0'
	implementation 'com.Android.support:appcompat-v7:23.0.0'
}

执行

gradlew :app:assembleDebug

命令 , 进行编译打包时 ;


在编译打包时 , 就会出现依赖冲突问题 ,

appcompat-v7 函数库依赖了 appcompat-v4 函数库 ,

fresco 函数库也同样依赖了 appcompat-v4 函数库 ,

这样就使得应用同时导入了 2 2 2 个 appcompat-v4 函数库 ;


在上一篇博客 【Android Gradle 插件】Gradle 依赖管理 ⑤ ( dependencies 依赖项拆分 | 依赖组 | 依赖名称 | 依赖版本号 | 动态指定依赖版本号 | 使用命令行查看模块 ) 中介绍了如果配置了两个相同的依赖 , 则选取较高版本的依赖库 ,

因此原理上 , 不会出现依赖冲突问题 ;





三、dependencies 依赖库层级分析



分析依赖问题 , 就需要查看依赖情况 , 在 Terminal 面板中执行

gradlew :app:dependencies

命令 , 查看依赖的情况 , 逐个排查依赖冲突问题 ;

在输出日志中 , 可以查看顶层依赖库 , 与依赖库的依赖库之间的依赖关系 ;

com.android.support.constraint:constraint-layout:2.0.1 是顶层依赖库 ,

+--- com.android.support.constraint:constraint-layout:2.0.1

该依赖库又依赖了 com.android.support:appcompat-v7:28.0.0 依赖库 ,

+--- com.android.support.constraint:constraint-layout:2.0.1
|    +--- com.android.support:appcompat-v7:28.0.0

com.android.support:appcompat-v7:28.0.0 依赖库 又依赖了 com.android.support:support-annotations:28.0.0 com.android.support:support-compat:28.0.0 等依赖库 ;

+--- com.android.support.constraint:constraint-layout:2.0.1
|    +--- com.android.support:appcompat-v7:28.0.0
|    |    +--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:support-compat:28.0.0

完整的依赖库层级如下 :

debugCompileClasspath - Resolved configuration for compilation for variant: debug
+--- com.android.support.constraint:constraint-layout:2.0.1
|    +--- com.android.support:appcompat-v7:28.0.0
|    |    +--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:support-compat:28.0.0
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:collections:28.0.0
|    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    +--- android.arch.lifecycle:runtime:1.1.1
|    |    |    |    +--- android.arch.lifecycle:common:1.1.1
|    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    +--- android.arch.core:common:1.1.1
|    |    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    \--- com.android.support:versionedparcelable:28.0.0
|    |    |         +--- com.android.support:support-annotations:28.0.0
|    |    |         \--- com.android.support:collections:28.0.0 (*)
|    |    +--- com.android.support:collections:28.0.0 (*)
|    |    +--- com.android.support:cursoradapter:28.0.0
|    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:support-core-utils:28.0.0
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:documentfile:28.0.0
|    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:loader:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    +--- android.arch.lifecycle:livedata:1.1.1
|    |    |    |    |    +--- android.arch.core:runtime:1.1.1
|    |    |    |    |    |    +--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    |    |    |    \--- android.arch.core:common:1.1.1 (*)
|    |    |    |    |    +--- android.arch.lifecycle:livedata-core:1.1.1
|    |    |    |    |    |    +--- android.arch.lifecycle:common:1.1.1 (*)
|    |    |    |    |    |    +--- android.arch.core:common:1.1.1 (*)
|    |    |    |    |    |    \--- android.arch.core:runtime:1.1.1 (*)
|    |    |    |    |    \--- android.arch.core:common:1.1.1 (*)
|    |    |    |    \--- android.arch.lifecycle:viewmodel:1.1.1
|    |    |    |         \--- com.android.support:support-annotations:26.1.0 -> 28.0.0
|    |    |    +--- com.android.support:localbroadcastmanager:28.0.0
|    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    \--- com.android.support:print:28.0.0
|    |    |         \--- com.android.support:support-annotations:28.0.0
|    |    +--- com.android.support:support-fragment:28.0.0
|    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    +--- com.android.support:support-core-ui:28.0.0
|    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    +--- com.android.support:support-core-utils:28.0.0 (*)
|    |    |    |    +--- com.android.support:customview:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    \--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    +--- com.android.support:viewpager:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    |    +--- com.android.support:coordinatorlayout:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    |    +--- com.android.support:drawerlayout:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    |    +--- com.android.support:slidingpanelayout:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    \--- com.android.support:customview:28.0.0 (*)
|    |    |    |    +--- com.android.support:interpolator:28.0.0
|    |    |    |    |    \--- com.android.support:support-annotations:28.0.0
|    |    |    |    +--- com.android.support:swiperefreshlayout:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    +--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    |    \--- com.android.support:interpolator:28.0.0 (*)
|    |    |    |    +--- com.android.support:asynclayoutinflater:28.0.0
|    |    |    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    |    |    \--- com.android.support:support-compat:28.0.0 (*)
|    |    |    |    \--- com.android.support:cursoradapter:28.0.0 (*)
|    |    |    +--- com.android.support:support-core-utils:28.0.0 (*)
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    +--- com.android.support:loader:28.0.0 (*)
|    |    |    \--- android.arch.lifecycle:viewmodel:1.1.1 (*)
|    |    +--- com.android.support:support-vector-drawable:28.0.0
|    |    |    +--- com.android.support:support-annotations:28.0.0
|    |    |    \--- com.android.support:support-compat:28.0.0 (*)
|    |    \--- com.android.support:animated-vector-drawable:28.0.0
|    |         +--- com.android.support:support-vector-drawable:28.0.0 (*)
|    |         \--- com.android.support:support-core-ui:28.0.0 (*)
|    +--- com.android.support:support-compat:28.0.0 (*)
|    \--- com.android.support.constraint:constraint-layout-solver:2.0.1
+--- com.android.support:appcompat-v7:23.0.0 -> 28.0.0 (*)
+--- com.facebook.fresco:fresco:0.14.0
|    +--- com.facebook.fresco:drawee:0.14.0
|    |    \--- com.facebook.fresco:fbcore:0.14.0
|    +--- com.facebook.fresco:fbcore:0.14.0
|    \--- com.facebook.fresco:imagepipeline:0.14.0
|         +--- com.parse.bolts:bolts-tasks:1.4.0
|         +--- com.facebook.fresco:fbcore:0.14.0
|         \--- com.facebook.fresco:imagepipeline-base:0.14.0
|              +--- com.android.support:support-core-utils:24.2.1 -> 28.0.0 (*)
|              +--- com.parse.bolts:bolts-tasks:1.4.0
|              \--- com.facebook.fresco:fbcore:0.14.0
+--- com.android.support.constraint:constraint-layout:{
    
    strictly 2.0.1} -> 2.0.1 (c)
+--- com.android.support:appcompat-v7:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.facebook.fresco:fresco:{
    
    strictly 0.14.0} -> 0.14.0 (c)
+--- com.android.support:support-compat:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support.constraint:constraint-layout-solver:{
    
    strictly 2.0.1} -> 2.0.1 (c)
+--- com.android.support:support-annotations:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:collections:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:cursoradapter:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:support-core-utils:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:support-fragment:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:support-vector-drawable:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:animated-vector-drawable:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.facebook.fresco:drawee:{
    
    strictly 0.14.0} -> 0.14.0 (c)
+--- com.facebook.fresco:fbcore:{
    
    strictly 0.14.0} -> 0.14.0 (c)
+--- com.facebook.fresco:imagepipeline:{
    
    strictly 0.14.0} -> 0.14.0 (c)
+--- android.arch.lifecycle:runtime:{
    
    strictly 1.1.1} -> 1.1.1 (c)
+--- com.android.support:versionedparcelable:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:documentfile:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:loader:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:localbroadcastmanager:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:print:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:support-core-ui:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- android.arch.lifecycle:viewmodel:{
    
    strictly 1.1.1} -> 1.1.1 (c)
+--- com.parse.bolts:bolts-tasks:{
    
    strictly 1.4.0} -> 1.4.0 (c)
+--- com.facebook.fresco:imagepipeline-base:{
    
    strictly 0.14.0} -> 0.14.0 (c)
+--- android.arch.lifecycle:common:{
    
    strictly 1.1.1} -> 1.1.1 (c)
+--- android.arch.core:common:{
    
    strictly 1.1.1} -> 1.1.1 (c)
+--- android.arch.lifecycle:livedata:{
    
    strictly 1.1.1} -> 1.1.1 (c)
+--- com.android.support:customview:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:viewpager:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:coordinatorlayout:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:drawerlayout:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:slidingpanelayout:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:interpolator:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:swiperefreshlayout:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- com.android.support:asynclayoutinflater:{
    
    strictly 28.0.0} -> 28.0.0 (c)
+--- android.arch.core:runtime:{
    
    strictly 1.1.1} -> 1.1.1 (c)
\--- android.arch.lifecycle:livedata-core:{
    
    strictly 1.1.1} -> 1.1.1 (c)

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/han1202012/article/details/125020732