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
的目录不是项目根目录造成,切换到项目根目录执行该命令即可
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.
...
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.
...
C:\AndroidProjects\timer>gradlew :app:builClean
C:\AndroidProjects\timer>gradlew -v
------------------------------------------------------------
Gradle 7.0.2
------------------------------------------------------------
...
C:\AndroidProjects\timer>gradlew clean
# release和debug都会输出
C:\AndroidProjects\timer>gradlew build
C:\AndroidProjects\timer>gradlew installDebug
C:\AndroidProjects\timer>gradlew build --info
# 一般在根目录的build/reports/profile下
C:\AndroidProjects\timer>gradlew build --profile
```shell
C:\AndroidProjects\timer>gradlew build --info --debug --stacktrace
```
```shell
C:\AndroidProjects\timer>gradlew assembleRelease
# 简化命令
C:\AndroidProjects\timer>gradlew aR
```
```shell
C:\AndroidProjects\timer>gradlew installRelease
```
```shell
C:\AndroidProjects\timer>gradlew uninstallRelease
```
```shell
C:\AndroidProjects\timer>gradlew dependencies
```
```shell
C:\AndroidProjects\timer>gradlew app:dependencies
```