Android Gradle 插件Gradle 依赖管理 ⑧ ( implementation fileTree 引入jar文件依赖 | implementation files 引入文件依赖 )
Posted 韩曙亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android Gradle 插件Gradle 依赖管理 ⑧ ( implementation fileTree 引入jar文件依赖 | implementation files 引入文件依赖 )相关的知识,希望对你有一定的参考价值。
文章目录
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
一、implementation fileTree 引入目录下的文件作为依赖
org.gradle.api.Project 配置 ( build.gradle 根配置 ) 文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
在 build.gradle#dependencies 配置中 , 使用 implementation fileTree 引入文件树 , 将当前目录中 libs 目录下的所有 .jar 后缀的文件添加到依赖中 ;
dependencies
implementation fileTree(include: ['*.jar'], dir: 'libs')
fileTree 函数原型定义在 org.gradle.api.Project 配置中 , 在 Project 中提供了 4 4 4 种重载方法 ;
ConfigurableFileTree fileTree(Object baseDir)
Creates a new ConfigurableFileTree using the given base directory.
ConfigurableFileTree fileTree(Object baseDir, Closure configureClosure)
Creates a new ConfigurableFileTree using the given base directory.
ConfigurableFileTree fileTree(Object baseDir, Action<? super ConfigurableFileTree> configureAction)
Creates a new ConfigurableFileTree using the given base directory.
ConfigurableFileTree fileTree(Map<String,?> args)
Creates a new ConfigurableFileTree using the provided map of arguments.
文档位置 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#fileTree-java.lang.Object-
二、implementation files 引入目录下的文件作为依赖
org.gradle.api.Project 配置 ( build.gradle 根配置 ) 文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
在 build.gradle#dependencies 配置中 , 使用 implementation files 引入多个文件 , 将这些文件添加到依赖中 ;
dependencies
implementation files('libs/ffmpeg.jar', 'libs/location.jar')
files 函数原型定义在 org.gradle.api.Project 配置中 , 在 Project 中提供了 3 3 3 种重载方法 ;
注意 file 函数只能指定一个文件 ;
File file(Object path)
Resolves a file path relative to the project directory of this project.
File file(Object path, PathValidation validation)
Resolves a file path relative to the project directory of this project and validates it using the given scheme.
ConfigurableFileCollection files(Object... paths)
Returns a ConfigurableFileCollection containing the given files.
ConfigurableFileCollection files(Object paths, Closure configureClosure)
Creates a new ConfigurableFileCollection using the given paths.
ConfigurableFileCollection files(Object paths, Action<? super ConfigurableFileCollection> configureAction)
Creates a new ConfigurableFileCollection using the given paths.
参考文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html#files-java.lang.Object…-
以上是关于Android Gradle 插件Gradle 依赖管理 ⑧ ( implementation fileTree 引入jar文件依赖 | implementation files 引入文件依赖 )的主要内容,如果未能解决你的问题,请参考以下文章
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 扩展 )