SuperAPI AI 工具集

flutter-app-size

编程与开发

查看项目

更新于 10-16 05:47

技能介绍

用途:分析并优化 Flutter 应用体积,通过测量构建产物、生成体积分析报告、借助 Dart DevTools 拆解组件,并实施体积缩减策略(调试信息分离、资源压缩、平台级 tree-shaking)。前提是已配置 Flutter 环境且目标平台可用。

主要能力与用法:

  1. 测量 Android 或桌面(Linux/macOS/Windows):运行 flutter build <platform> --analyze-size,会在 build/ 目录生成 -code-size-analysis_.json 并输出高层摘要。
  2. 测量 iOS:运行 flutter build ipa --export-method development,再在 Xcode 中打开 build/ios/archive/*.xcarchive,经 Distribute App -> Development,在 App Thinning 中选择 all compatible device variants 并 Strip Swift symbols,导出 IPA 后查看 App Thinning Size Report.txt。
  3. 组件拆解:运行 dart devtools,在 App Size Tool 中上传 -code-size-analysis_.json,用 Treemap 或 Dominator Tree 找出体积较大的包、库或资源。
  4. 缩减策略:使用 flutter build appbundle --obfuscate --split-debug-info=build/app/outputs/symbols/ 分离调试符号;用 dart:io 的 Platform 检查让 AOT 编译器剔除目标平台不可达代码;压缩资源。
  5. 验证:重新生成分析文件,在 DevTools 的 Diff 标签对比前后体积。

限制:不要用 debug 构建(flutter run 或 IDE 播放按钮)测量体积;不要假设上传包体积等于用户实际下载体积;--split-debug-info 必须提供有效目录路径;iOS 不要只看 .app 体积,应以 App Thinning Size Report 为准;Platform 检查需直接使用 dart:io 常量以便 tree-shaking。