持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第28天,点击查看活动详情
Gradle 快速构建命令
Gradle 提供了一系列的快速构建命令来替代 IDE 的可视化构建操作,如我们最常用的 clean、build 等等。需要注意的是,build 命令会把 debug、release 环境的包都构建出来。
查看构建版本
./gradlew -v
清除 build 文件夹
./gradlew clean
检查依赖并编译打包
./gradlew build
编译并安装 debug 包
./gradlew installDebug
编译并打印日志
./gradlew build --info
编译并输出性能报告,性能报告一般在构建工程根目录 build/reports/profile 下
./gradlew build --profile
调试模式构建并打印堆栈日志
./gradlew build --info --debug --stacktrace
强制更新最新依赖,清除构建后再构建
./gradlew clean build --refresh-dependencies
编译并打 Debug 包
./gradlew assembleDebug
简化版命令,取各个单词的首字母 ./gradlew aD
编译并打 Release 的包
./gradlew assembleRelease
简化版命令,取各个单词的首字母 ./gradlew aR
Gradle 构建并安装命令
Release 模式打包并安装
./gradlew installRelease
卸载 Release 模式包
./gradlew uninstallRelease
debug release 模式全部渠道打包
./gradlew assemble
Gradle 查看包依赖命令
查看项目根目录下的依赖
./gradlew dependencies
查看 app 模块下的依赖
./gradlew app:dependencies 复制代码
查看 app 模块下包含 implementation 关键字的依赖项目
./gradlew app:dependencies --configuration implementation
Gradle构建诊断工具
Profile report
使用如下命令生成一份本地的构建报告:
./gradlew assembleDebug --profile
Summary
Gradle 构建信息的概览界面,用于 查看 Total Build Time、初始化(包含 Startup、Settings and BuildSrc、Loading Projects 三部分)、配置、任务执行的时间。如下图所示:
Configuaration
Gradle 配置各个工程所花费的时间,我们可以看到 All projects、app 模块以及其它模块单个的配置时间。如下图所示:
Dependency Resolution
Gradle 在对各个 task 进行依赖关系解析时所花费的时间。如下图所示:
Task Execution
Gradle 在执行各个 Gradle task 所花费的时间。如下图所示:
Task Execution 的时间是所有 gradle task 执行时间的总和,实际上 多模块的任务是并行执行的。