【Android Gradle 插件】Gradle 依赖管理 ⑧ ( implementation fileTree 引入jar文件依赖 | implementation files 引入文件依赖 )

Android Plugin DSL Reference 参考文档 :





一、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…-

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值