Gradle常用命令

Gradle 常用命令

0x01 快速构建命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 查看构建版本
./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 aDR --offline

# 守护进程
./gradlew build --daemon

# 并行编译模式
./gradlew build --parallel --parallel-threads=N

0x02 构建并安装命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 编译并打Debug包
./gradlew assembleDebug

# 这个是简写 assembleDebug
./gradlew aD

# 编译并打Release的包
./gradlew assembleRelease

# 这个是简写 assembleRelease
./gradlew aR

# Debug模式打包并安装
./gradlew install app:assembleDebug

# Release模式打包并安装
./gradlew installRelease

# 卸载Release模式包
./gradlew uninstallRelease

# Flavor渠道包
./gradlew install app:assemble<Flavor>Debug

0x03 查看包依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
./gradlew dependencies

# 查看app模块依赖
./gradlew app:dependencies

# 检索依赖库
./gradlew app:dependencies | grep CompileClasspath

# windows 没有 grep 命令
./gradlew app:dependencies | findstr "CompileClasspath"

# 将检索到的依赖分组找到 比如flavorDebugCompileClasspath就是flavor渠道分发的开发编译依赖
./gradlew app:dependencies --configuration <flavor>DebugCompileClasspath

# 依赖树过长可以保存到本地文件方便查看
./gradlew app:dependencies --configuration <flavor>DebugCompileClasspath >1.log

0x04 依赖包更新

1
2
3
4
5
# 依赖包更新命令
./gradlew build --refresh-dependencies

# 强制更新最新依赖,清除构建并构建
./gradlew clean build --refresh-dependencies
作者

Dench

发布于

2020-02-28

更新于

2020-02-28

许可协议

CC BY-NC-SA 4.0

Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×