当前位置:   article > 正文

AS 之 gradle 命令_as命令行卸载项目

as命令行卸载项目

1、命令大全

  • 当我们想知道一个工具有哪些命令的时候,最简单直接的方式就是使用 help 命令查看支持哪些,然后从中找到我们想要的
  • 执行: ./gradlew --help

2、编译命令

2.1 检查依赖并编译打包
  • ./gradlew build
2.2 编译并打 Debug 包
  • ./gradlew assembleDebug or /gradlew aD
2.3 编译打出 Debug 包并安装
  • ./gradlew installDebug or /gradlew iD
2.4 编译并打出 Release 包
  • ./gradlew assembleRelease or /gradlew aR
2.5 编译打出 Release 包并安装
  • ./gradlew installRelease or /gradlew iR
2.6 Debug/Release 编译并打印日志
  • ./gradlew assembleDebug --info or ./gradlew assembleRelease --info

3、清除命令

  • 清除构建目录下的产物:./gradlew clean
  • 等同于 Build -> Clean Project

4、卸载命令

4.1 卸载 Debug/Release 安装包
  • ./gradlew uninstallDebug or ./gradlew uninstallRelease
  • 输出:
Uninstalling com.yechaoa.gradlex (from app:debug) from device 'Pixel_5_API_31(AVD) - 12' (emulator-5554).
Uninstalled com.yechaoa.gradlex from 1 device
  • 1
  • 2
4.2 adb 卸载
  • 在 Android Studio 中执行是直接卸载的当前项目安装包,如果是 adb 执行则需要指定包名
    adb uninstall com.autopai.smart.sound.effect

5、调试命令

  • 调试命令在定位编译问题的时候非常有用
  • 当我们遇到编译错误的时候,经常会看到这个提示:
* Try:
> Run gradle tasks to get a list of available tasks.
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
  • 1
  • 2
  • 3
  • 4
  • 5
5.1 编译并打印堆栈日志
  • ./gradlew assembleDebug --stacktrace or ./gradlew assembleDebug -s
  • 详细版:
    ./gradlew assembleDebug --full-stacktrace or ./gradlew assembleDebug -S
5.2 日志级别
  • 有时候构建日志会有很多,看到的可能不全,甚至不是真正的编译问题,而构建日志又不能像 logcat 那样可以可视化的筛选,这个时候就需要用日志级别来筛选一下
-q,--quiet
仅记录错误。

-w,--warn
将日志级别设置为警告。

-i,--info
将日志级别设置为信息。

-d,--debug
调试模式(包括正常的stacktrace)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 示例:
    ./gradlew assembleDebug -w

6、任务相关

6.1 查看主要 Task
  • ./gradlew tasks
6.2 查看所有 Task
  • ./gradlew tasks --all
6.3 执行 Task
  • ./gradlew taskName or ./gradlew :moduleName:taskName
  • 同时,可在 AS 右侧工具类 Gradle 面板中查看项目及 module 的 Task,并可以点击执行对应 Task
    image

7、查看依赖

7.1 查看项目根目录下的依赖
  • ./gradlew dependencies
7.2 查看 app 模块下的依赖
  • ./gradlew app:dependencies
7.3 查看依赖输出到文件
  • ./gradlew app:dependencies > dependencies.txt
    image

8、参考资料

  • Gradle 常用的几十个命令:https://mp.weixin.qq.com/s/oYQTl5bc8yC2xdjPjJAtRQ
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/296371
推荐阅读
相关标签
  

闽ICP备14008679号