Android Plugin DSL Reference 参考文档 :
org.gradle.api.Project 配置 ( build.gradle 根配置 ) 文档 : https://docs.gradle.org/current/javadoc/org/gradle/api/Project.html
在 Android Studio 工程中的 Module 下的 build.gradle 的配置 , 其根配置就是 org.gradle.api.Project 配置 ,
build.gradle 中常见的
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
// 矢量图支持库 , 支持 5.0 以下版本手机使用矢量图 , 这个是创建应用时自带的配置
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
配置 的原型是 org.gradle.api.Project 配置中的 dependencies 方法 , 传入闭包作为参数 ,
dependencies 方法原型如下 :
@HasInternalProtocol
public interface Project extends Comparable<Project>, ExtensionAware, PluginAware {
/**
* <p>Configures the dependencies for this project.
*
* <p>This method executes the given closure against the {@link DependencyHandler} for this project. The {@link
* DependencyHandler} is passed to the closure as the closure's delegate.
*
* <h3>Examples:</h3>
* See docs for {@link DependencyHandler}
*
* @param configureClosure the closure to use to configure the dependencies.
*/
void dependencies(Closure configureClosure);
}
dependencies 闭包中的 implementation 实际上是调用了 DependencyHandler 的 add 方法 ,
DependencyHandler # add 方法原型如下 : 该 add 方法有 2 个参数 和 3 个参数 两种重载函数 ,
@Nullable
Dependency add(String configurationName,
Object dependencyNotation)
Adds a dependency to the given configuration.
Parameters:
configurationName - The name of the configuration.
dependencyNotation - The dependency notation, in one of the notations described above.
Returns:
The dependency, or null if dependencyNotation is a provider.
Dependency add(String configurationName,
Object dependencyNotation,
Closure configureClosure)
Adds a dependency to the given configuration, and configures the dependency using the given closure.
Parameters:
configurationName - The name of the configuration.
dependencyNotation - The dependency notation, in one of the notations described above.
configureClosure - The closure to use to configure the dependency.
Returns:
The dependency, or null if dependencyNotation is a provider.
对应文档地址 : https://docs.gradle.org/current/javadoc/org/gradle/api/artifacts/dsl/DependencyHandler.html
add 方法参数介绍 :
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有