【Android Gradle 插件】Module 目录下 build.gradle 配置文件 ( plugins 闭包代码块中引入插件 | PluginAware#apply 方法引入插件 )
2023-06-13 09:18:01 时间
文章目录
Android Plugin DSL Reference 参考文档 : https://google.github.io/android-gradle-dsl/2.3/
一、Module 目录下 build.gradle 配置文件
1、plugins 闭包代码块中引入插件
在 Module 目录下的 build.gradle 中 , 首先引入插件 :
plugins {
id 'com.android.application'
}
此处调用了 PluginDependenciesSpec 中的 id 方法 , 方法原型如下 , 该 id 方法 , 接收一个 String 参数 , 在闭包中配置要引入的插件 ;
id 方法原型 :
/**
* 用于声明要在脚本中使用的插件的DSL。
* <p>
* 在构建脚本中,<code>plugins {}</code>脚本块API就是这种类型的。
* 也就是说,您可以在plugins脚本块的主体中使用这个API来声明要用于脚本的插件。
*/
public interface PluginDependenciesSpec {
/**
* 在具有给定id的插件上添加依赖项。
*
* <pre>
* plugins {
* id "org.company.myplugin"
* }
* </pre>
*
* 这对于重用插件中的任务类或将其应用于当前脚本以外的其他目标非常有用。
*
* @param id 要依赖的插件的id
* @return 一个可变插件依赖项规范,可用于进一步细化依赖项
*/
PluginDependencySpec id(String id);
}
闭包中配置插件的格式为 id 插件名称
id 'com.android.application'
2、PluginAware#apply 方法引入插件
还有一种引入插件的方式就是使用
apply plugin: 'com.android.application'
代码 , 调用的是 PluginAware 接口的 apply 方法 , 传入一个 Map 集合作为参数 ;
public interface PluginAware {
void apply(Map<String, ?> var1);
}
Lsn13 17.56
相关文章
- android onresume方法,非静态方法’onResume’Android Studio
- 代码加密 android,Android 开发怎样做代码加密或混淆「建议收藏」
- android activity自动跳转,Android activity跳转之finish()方法的作用
- Android service ( 一 ) 三种开启服务方法
- android线程间通信的几种方法_Android进程间和线程间通信方式
- Android平台GB28181设备接入端语音广播支持PS格式
- 【Android 安全】DEX 加密 ( 代理 Application 开发 | 加载 dex 文件 | 使用反射获取方法创建本应用的 dexElements | 各版本创建 dex 数组源码对比 )
- 【错误记录】Android Studio 编译报错 ( Could not find com.android.tools.build:gradle:4.2.1. )
- 【错误记录】Android Studio 编译报错 ( Could not install Gradle distribution from ‘https://services.gradle.or )
- 【错误记录】Android Gradle 配置报错 ( gradle.properties 配置到 BuildConfig 中需要注意类型转换 | 位置: 类 BuildConfig )
- 【Android Gradle 插件】LintOptions 配置 ③ ( LintOptions#error 方法配置 | Lint 问题 ID | 查询 Lint 问题 ID 列表 )
- 【Android Gradle 插件】TestOptions 配置 ④ ( org.gradle.api.tasks.testing.Test 单元测试配置类 | Android 单元测试示例 )
- 【Android Gradle 插件】Gradle 依赖管理 ③ ( build.gradle#dependencies 依赖分组 | configurations 自定义依赖分组 )
- 【Android UI】贝塞尔曲线 ④ ( 使用 android.graphics.Path 提供的 cubicTo 方法绘制三阶贝塞尔曲线示例 )
- 【Android Gradle 插件】Gradle 扩展属性 ② ( 定义在根目录 build.gradle 中的扩展属性 | 使用 rootProject.扩展属性名访问 | 扩展属性示例 )
- 【Android Gradle 插件】Gradle 基础配置 ③ ( 生成 Gradle Wrapper 配置 | 分析生成的 gradle-wrapper.properties 配置文件 )
- 【错误记录】Android Studio 集成 ARoute 编译报错 ( 兼容 support 库和 androidx 库 | add ‘tools:replace=“android:appCo )
- 解析linux或android添加文件系统的属性接口的方法
- Android自动打包工具aapt详解手机开发
- Android将androidview的位置设为右下角的解决方法
- android图库竖屏不显示statusbar的解决方法
- android将搜索引擎设置为中国雅虎无法搜索问题解决方法
- Android读写文件方法汇总
- android杂记:C++文件的添加log方法分享
- logcat命令使用方法和查看android系统日志缓冲区内容的方法
- Android实现检查并下载APK更新、安装APK及获取网络信息的方法
- Android提高之多级树形菜单的实现方法