Android Gradle 插件Gradle 依赖管理 ⑥ ( dependencies 依赖查找路径 | dependencies 依赖冲突 | dependencies 依赖库层级分析 )
Posted 韩曙亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Gradle 插件Gradle 依赖管理 ⑥ ( dependencies 依赖查找路径 | dependencies 依赖冲突 | dependencies 依赖库层级分析 )相关的知识,希望对你有一定的参考价值。
文章目录
Android Plugin DSL Reference 参考文档 :
-
Android Studio 构建配置官方文档 : https://developer.android.google.cn/studio/build
-
添加构建依赖项 参考文档 : https://developer.android.google.cn/studio/build/dependencies
-
Android Gradle 插件配置与 Gradle 配置关联 : 【Android Gradle 插件】Gradle 依赖管理 ① ( org.gradle.api.Project 配置 | Android Gradle 插件配置与 Gradle 配置关联 ) ★
-
Android Gradle 插件文档主页 : https://google.github.io/android-gradle-dsl/2.3/
-
BaseExtension 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.BaseExtension.html
-
AppExtension ( build.gradle#android 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.AppExtension.html
-
build.gradle#android 模块配置文档 : android-gradle-dsl/2.3/com.android.build.gradle.AppExtension.html
-
ProductFlavor ( build.gradle#android#defaultConfig 配置 ) 文档 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.ProductFlavor.html
-
ProductFlavor#externalNativeBuild 配置 ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) : com.android.build.gradle.internal.dsl.ProductFlavor:externalNativeBuild
-
ExternalNativeBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.ExternalNativeBuildOptions.html
-
NdkBuildOptions ( build.gradle#android#defaultConfig#externalNativeBuild#ndkBuild 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.NdkBuildOptions.html
-
CmakeOptions ( build.gradle#android#defaultConfig#externalNativeBuild#cmake 配置 ) 文档位置 : android-gradle-dsl-gh-pages/2.3/com.android.build.gradle.internal.dsl.CmakeOptions.html
-
JackOptions ( build.gradle#android#defaultConfig#jackOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.JackOptions.html
-
AnnotationProcessorOptions ( 注解处理器配置 ) ( build.gradle#android#defaultConfig#javaCompileOptions配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AnnotationProcessorOptions.html
-
NdkOptions ( build.gradle#android#defaultConfig#ndk 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.NdkOptions.html
-
NDK 参考文档 : Add C and C++ Code to Your Project.
-
VectorDrawablesOptions ( build.gradle#android#defaultConfig#vectorDrawables 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.VectorDrawablesOptions.html
-
BuildType ( build.gradle#android#buildTypes 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.BuildType.html
-
SigningConfig ( build.gradle#android#signingConfigs 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.SigningConfig.html
-
AaptOptions ( build.gradle#android#aaptOptions 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AaptOptions.html
-
AndroidSourceSets ( build.gradle#android#sourceSets 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceSet.html
-
AndroidSourceDirectorySet ( build.gradle#android#sourceSets#aidl/assets/java/jni/jniLibs 配置 ) 文档位置 :android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceDirectorySet.html
-
AndroidSourceFile ( build.gradle#android#sourceSets#manifest 配置 ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.api.AndroidSourceFile.html
-
DataBindingOptions ( build.gradle#android#dataBinding ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DataBindingOptions.html
-
DexOptions ( build.gradle#android#dexOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DexOptions.html
-
LintOptions ( build.gradle#android#lintOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.LintOptions.html
-
PackagingOptions ( build.gradle#android#packagingOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.PackagingOptions.html
-
Splits ( build.gradle#android#splits ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.Splits.html
-
AbiSplitOptions ( build.gradle#android#splits#abi ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.AbiSplitOptions.html
-
LanguageSplitOptions ( build.gradle#android#splits#language ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.LanguageSplitOptions.html
-
DensitySplitOptions ( build.gradle#android#splits#density ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.DensitySplitOptions.html
-
TestOptions ( build.gradle#android#testOptions ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.TestOptions.html
-
Android 测试相关文档 : https://developer.android.google.cn/training/testing
-
UnitTestOptions ( build.gradle#android#testOptions#unitTests ) 文档位置 : android-gradle-dsl/2.3/com.android.build.gradle.internal.dsl.TestOptions.UnitTestOptions.html
-
org.gradle.api.tasks.testing.Test 单元测试配置类 : https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/Test.html
-
LibraryExtension ( Library 依赖库的 build.gradle#android 配置 ) 文档 : android-gradle-dsl/2.3/com.android.build.gradle.LibraryExtension.html
-
org.gradle.api.Project 配置 ( build.gradle 根配置 ) 文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
-
org.gradle.api.artifacts.dsl.DependencyHandler 配置 ( build.gradle#dependencies#implementation 配置 ) : https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html
-
添加构建依赖项 参考文档 : https://developer.android.google.cn/studio/build/dependencies
一、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
| | | | | +--以上是关于Android Gradle 插件Gradle 依赖管理 ⑥ ( dependencies 依赖查找路径 | dependencies 依赖冲突 | dependencies 依赖库层级分析 )的主要内容,如果未能解决你的问题,请参考以下文章
Android Gradle 插件Gradle 依赖管理 ① ( org.gradle.api.Project 配置 | Android Gradle 插件配置与 Gradle 配置关联 ) ★
Android Gradle 插件Gradle 构建机制 ⑤ ( 在 Android Studio 中查看 Android Gradle 插件源码 )
Android Gradle 插件Gradle 自定义 Plugin 插件 ② ( buildSrc 目录中实现 Gradle 插件 | 实现 Gradle 插件代码 | 模块引入插件并编译 )
Android Gradle 插件Android Module 模块 build.gradle 构建脚本 Groovy 语法分析 ① ( Gradle 二进制插件引入 | Gradle依赖配置 )
Android Gradle 插件Android Module 模块 build.gradle 构建脚本 Groovy 语法分析 ① ( Gradle 二进制插件引入 | Gradle依赖配置 )
Android Gradle 插件Gradle 自定义 Plugin 插件 ③ ( 自定义插件作用 | Android Gradle 插件的扩展 | 自定义 Extension 扩展 )