文章目录
- 一、dependencies 依赖传递层级
- 二、transitive 关闭依赖传递配置
- 三、exclude 排除子依赖配置
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 依赖传递层级
在上一篇博客中 , 执行
代码语言:javascript复制gradlew :app:dependencies
命令 , 可以打印出依赖库以及依赖库的依赖库层级 ,
代码语言:javascript复制 --- 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
默认情况下 , 在 build.gradle 中配置 com.facebook.fresco:fresco:0.14.0
依赖 ,
dependencies {
implementation 'com.facebook.fresco:fresco:0.14.0'
}
会自动将其子依赖库 com.facebook.fresco:drawee:0.14.0
, com.facebook.fresco:fbcore:0.14.0
, com.facebook.fresco:imagepipeline:0.14.0
也会加载进来 ;
二、transitive 关闭依赖传递配置
如果我们不想要解析其子依赖 , 如在其它位置已经有了该依赖 , 则可以进行如下设置 :
代码语言:javascript复制dependencies {
implementation 'com.facebook.fresco:fresco:0.14.0', {
transitive false
}
}
在依赖后 , 增加一个闭包 , 使用逗号隔开 ,
在闭包中配置 transitive false
选项 , 即不解析该依赖的子依赖 ;
进行了上述设置后 , 调用 fresco 函数库肯定会出现问题 ;
三、exclude 排除子依赖配置
设置 exclude 属性 , 可以排除依赖库的某个子依赖 , 并且在外部进行依赖 , 可以有效解决依赖库冲突问题 ;
代码语言:javascript复制dependencies {
implementation 'com.facebook.fresco:fresco:0.14.0', {
transitive true
// 排除 com.android.support:support-core-utils:24.2.1 子依赖库
exclude(group:'com.android.support', module:'support-core-utils')
}
// 外部单独添加被排除的 com.android.support:support-core-utils:24.2.1 依赖库
implementation com.android.support:support-core-utils:24.2.1
}