文章目录
1. 环境配置
C:\Users\Administrator>gradle
JAVA_HOME is set to an invalid directory
这个问题是由于JAVA_HOME的目录带了bin,以及gradle目录带了bin,导致,把两个的配置路径都去掉\bin
即可
Settings -> Build,Execution,Deployment -> Build Tools -> Gradle
Gradle user home:C:/Users/Administrator/.gradle
-->
wrapper\dists\gradle-7.0.2-all\7era6s5ay7zsbhuvl0oc9g94s\gradle-7.0.2
C:\Users\Administrator>gradle
'gradle' 不是内部或外部命令,也不是可运行的程序或批处理文件。
这个坑是由于当前执行gradle
或者gradlew
的目录不是项目根目录造成,切换到项目根目录执行该命令即可
2. 查看主要任务
C:\AndroidProjects\timer>gradlew tasks
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project 'timer'
------------------------------------------------------------
Android tasks
-------------
androidDependencies - Displays the Android dependencies of the project.
signingReport - Displays the signing info for the base and test modules
sourceSets - Prints out all the source sets defined in this project.
...
3. 查看所有任务,包括缓存任务
C:\AndroidProjects\timer>gradlew tasks --all
> Task :tasks
------------------------------------------------------------
Tasks runnable from root project 'timer'
------------------------------------------------------------
Android tasks
-------------
app:androidDependencies - Displays the Android dependencies of the project.
app:signingReport - Displays the signing info for the base and test modules
app:sourceSets - Prints out all the source sets defined in this project.
...
4. 执行某个module的某个task
C:\AndroidProjects\timer>gradlew :app:builClean
5. 快捷命令-查看版本
C:\AndroidProjects\timer>gradlew -v
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------
...
6. 快捷命令-清除build文件夹(包括app下的build)
C:\AndroidProjects\timer>gradlew clean
7. 检查依赖并编译打包
# release和debug都会输出
C:\AndroidProjects\timer>gradlew build
8. 编译并安装debug包
C:\AndroidProjects\timer>gradlew installDebug
9. 编译并打印日志
C:\AndroidProjects\timer>gradlew build --info
10. 编译并输出性能报告
# 一般在根目录的build/reports/profile下
C:\AndroidProjects\timer>gradlew build --profile
11. 调试模式构建并打印堆栈日志
```shell
C:\AndroidProjects\timer>gradlew build --info --debug --stacktrace
```
12. 编译并打release包(debug同理)
```shell
C:\AndroidProjects\timer>gradlew assembleRelease
# 简化命令
C:\AndroidProjects\timer>gradlew aR
```
13. 安装release
```shell
C:\AndroidProjects\timer>gradlew installRelease
```
14. 卸载release
```shell
C:\AndroidProjects\timer>gradlew uninstallRelease
```
15. 查看根目录下依赖
```shell
C:\AndroidProjects\timer>gradlew dependencies
```
16. 查看app目录下依赖
```shell
C:\AndroidProjects\timer>gradlew app:dependencies
```