综述
LifeCycle
Initialization
Gradle supports single and multi-project builds. During the initialization phase, Gradle determines which projects are going to take part in the build, and creates a Project instance for each of these projects.
确定参与构建的项目,为每个项目创建一个project
实例。Android中就是根据setting.grade
中声明的项目来创建。具体步骤见下面CoreType-Project。
Configuration
During this phase the project objects are configured. The build scripts of all projects which are part of the build are executed.
执行每个项目自己的build scripts构建脚本。Android中就是执行个module中的build.grade
。
Execution
Gradle determines the subset of the tasks, created and configured during the configuration phase, to be executed. The subset is determined by the task name arguments passed to the gradle
command and the current directory. Gradle then executes each of the selected tasks.
决定要执行的任务的子集(第二阶段中创建和配置的)。
CoreType
Project
Gradle对外的接口,通过这个接口来编程使用Gradle的各种功能。
Project和build.gradle
文件是一对一关系,在Initialization
时期,Gradle会为每个参与构建的项目创建一个project
实例。步骤如下:
为本次构造创建一个
Settings
实例读取
settings.gradle
来配置上面的Settings
对象- 通过上面的
Settings
对象来创建Project
实例 - 执行每个项目的
build.gradle
来配置每个Project
实例
Task
Project
可以算是由一堆Task
构成的集合。每个Task
各司其职,比如编译代码、跑单元测试、压缩对齐等。
TaskContainer.create(java.lang.String)
)是用来添加Task
的,通过TaskCollection.getByName(java.lang.String)
)也可以获取到某个具体的Task
实例。
Plugins
Plugins
可以用于模块化与项目配置复用。
Plugins can be applied using the PluginAware.apply(java.util.Map)
) method, or by using the PluginDependenciesSpec
plugins script block.
Android 编译流程
图例可以看之前的博客
这里主要基于Gradle的命令展开
用Gradle打个debug包的命令如下,—info是为了打印出详细信息 并输出到文件 方便观察
./gradlew –info assembleDebug > ~/Desktop/gradle.info
开始一步步看日志吧
Initialization
读取settings
1 | Starting Build |
Configuration
1 | > Configure project : |
1 | All projects evaluated. |
Execution
log太多自行查看 就是执行上面的task
参考
写给 Android 开发者的 Gradle 系列(一)基本姿势