End

Flutter 常用命令 CLI

本文地址


目录

Flutter 常用命令 CLI

官方地址中文地址 的关系(中文网站一般都是以.cn结尾):

  • https://flutter.dev/xxx -> https://flutter.cn/xxx
  • https://docs.flutter.dev/xxx -> https://flutter.cn/docs/xxx
  • https://storage.googleapis.com/xxx -> https://storage.flutter-io.cn/xxx

常用命令

Flutter 的很多命令对各种格式都有支持,比如参数位置全拼简写单杠双杠...
Flutter 还会在你输入错误的命令时,智能提示你最接近的正确的命令

flutter -h         # 帮助信息【xx -h】【-h xx】【help xx】
flutter doctor     # 环境检测,只需要解决与你需求相关的问题即可,不需要全部都处理
flutter --version  # 查看 Flutter、Framework、Engine、Tools 版本信息
where flutter dart # 查看 Flutter、Dart 安装路径,确保 flutter\bin 目录在最前面

flutter channel    # 列出所有渠道(等价于分支),并标出当前使用的渠道
flutter channel xx # 切换到指定渠道:master/dev/beta/stable,建议 stable
flutter config xx  # 基础配置:启用/禁用平台,SDK/IDE 路径,默认设备
flutter upgrade    # 更新 Flutter SDK 和依赖包
flutter pub xx     # 依赖包管理,upgrade/add/remove/get/deps/outdated

flutter devices    # 可用的设备列表,比如 windows、chrome、edge、2413a0c5
flutter clean      # 删除 build/.dart_tool 目录,删除后的项目只剩 5M 左右
flutter create .   # 创建项目(app/module/package/plugin),或修复现有项目[常用]
flutter create --platforms=windows,macos,linux .      # 增加平台支持

flutter build xx   # 构建指定的产物【aar/apk/appbundle(仅GP可以使用)/bundle/web/windows】
flutter run xx     # 构建并启动/测试应用,-d 指定设备,--release/debug 构建类型
flutter attach     # 在一个正在运行的 flutter debug 应用上启用调试功能,如热重载、热启动

注意:web 应用 需要启动 Web 服务器,比如 npm serve,才能访问

flutter build aar

How to set Flutter build android aar version

flutter build aar --no-debug --no-profile --target-platform=android-arm64 --build-number=2.0
flutter build aar -h  # 显示详细帮助信息
flutter build aar -v  # 显示详细日志,包括所有 shell commands executed

Note: this command builds applications assuming that the entrypoint is lib/main.dart. This cannot currently be configured.

  • --[no-]debug:默认开,Build a debug version of the current project
  • --[no-]release:默认开,Build a release version of the current project
  • --[no-]profile:默认开,Build specialized for performance profiling 性能分析
  • --build-number:版本号,An identifier used as an internal version number
  • --target-platform:需要支持的目标平台
    • 默认支持 android-arm,即 armeabi-v7a (ARM 32 位)
    • 默认支持 android-arm64,即 arm64-v8a (ARM 64 位)
    • 默认支持 android-x64,即 x86-64 (x86 64 位)
    • 当前不支持 android-x86
  • --output-dir:存放生成的 repository 的绝对路径,默认为 <current-directory>android/build
  • --flavor:Supports the use of product flavors in Android Gradle scripts
  • --[no-]pub:默认开,Whether to run flutter pub get before executing this command
  • --split-debug-info=<v1.2.3/>:可减少包体积,不能和 --analyze-size 同时使用
  • --[no-]obfuscate:可用来混淆源代码,必须和 --split-debug-info 同时使用
  • --dart-define=<foo=bar>:传递附加的键值对常量
  • --android-project-arg:键值对直接传给 gradle 项目,可在 build.gradle 中通过 project.property 访问
  • --[no-]track-widget-creation:默认开,仅在 JIT 模式下有效
  • --[no-]null-assertions:执行空断言

flutter build apk

flutter build apk --release --target-platform=android-arm64 --build-number=88 --build-name=8.8
flutter build apk -h  # 显示详细帮助信息
flutter build apk -v  # 显示详细日志,包括所有 shell commands executed

在 module 项目中,使用 --build-number --build-name 参数是无效的,只有 application 项目中才有效

flutter build aar 相同/类似 的参数:

  • --debug
  • --release:默认模式
  • --profile
  • --build-number:必须是一个整数,对应 versionCode
  • --build-name=<x.y.z>:对应 versionName
  • --target-platform
  • --flavor
  • --[no-]pub
  • --split-debug-info=<v1.2.3/>
  • --[no-]obfuscate
  • --dart-define=<foo=bar>
  • --android-project-arg
  • --[no-]track-widget-creation
  • --[no-]null-assertions

新增的参数:

  • --target=<path>:The main entry-point file,默认为 lib\main.dart
  • --[no-]analyze-size:是否输出构件大小的分析信息,不能和 --split-debug-info 同时使用
  • --code-size-directory:code size analysis 文件的存放位置,默认在 build 目录下
  • --[no-]multidex:默认开
  • --ignore-deprecation:忽略使用废弃 API 时的警告
  • --split-per-abi:按 ABI 拆成独立的包,会根据支持的 ABI 打成多个 APK

flutter attach

调试功能

和在 IDE 中使用 flutter run flutter hot reload 等快捷命令一样,也可以在 命令行 中通过 flutter attach 命令使用所有 Flutter 的调试功能。

  • r热重载,Hot reload
  • R热重启,Hot restart
  • d取消连接,Detach, terminate "flutter run" but leave application running
  • q:终止程序,Quit, terminate the application on the device
  • c:清除屏幕,Clear the screen
  • s:屏幕截图:Save a screenshot to flutter.png
  • v打开开发工具,Open Flutter DevTools
  • h显示所有命令,List all available interactive commands
  • w:打印组件层级,Dump widget hierarchy to the console
  • t:打印渲染树,Dump rendering tree to the console
  • L:打印布局树,Dump layer tree to the console
  • o:切换操作系统,Simulate different operating systems
  • b:切换显示模式,Toggle platform brightness (dark and light mode)

The tool will search for a running Flutter app or module, if available. Otherwise, the tool will wait for the next Flutter app or module to launch before attaching.

2022-6-4

posted @ 2022-06-04 19:38  白乾涛  阅读(1391)  评论(2编辑  收藏  举报