npx skills add https://github.com/flutter/skills --skill flutter-app-size通过测量构建产物、生成大小分析报告、利用 Dart DevTools 进行组件分解,并实施特定的体积缩减策略(如调试信息分离、资源压缩和平台特定的摇树优化),来分析和优化 Flutter 应用程序的大小。假定已配置好 Flutter 环境且目标平台可用。
使用以下决策树来确定正确的测量和优化路径:
flutter build <platform> --analyze-size。然后进行 DevTools 分析。flutter build ipa --export-method development 并生成 Xcode App Thinning 大小报告,以获得准确的下载大小估算。dart devtools,打开 App Size Tool,并上传生成的 *-code-size-analysis_*.json 文件。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
--split-debug-info,压缩资源,并实现 Platform 检查以进行激进的摇树优化。确定目标平台和基线 请暂停并询问用户: "您针对哪个平台 (apk, appbundle, ios, linux, macos, windows) 进行大小优化,是否有具体的体积缩减目标?"
生成大小分析文件 执行带有 --analyze-size 标志的 Flutter build 命令,以编译 Dart 并记录代码大小使用情况。
flutter build <platform> --analyze-size
注意:这会在 build/ 目录下生成一个 *-code-size-analysis_*.json 文件,并在终端打印一个高级摘要。
生成 iOS 应用大小报告(仅限 iOS) 如果目标是 iOS,--analyze-size 生成的 .app 文件仅评估相对大小。要获得准确的最终用户下载大小估算,需要生成 Xcode 应用大小报告。
flutter build ipa --export-method development
* 后续指导用户:
1. 在 Xcode 中打开归档文件 (`build/ios/archive/*.xcarchive`)。
2. 点击 **Distribute App** -> **Development**。
3. 在 **App Thinning** 中,选择 "all compatible device variants"。
4. 选择 **Strip Swift symbols**。
5. 导出 IPA 并查看 `App Thinning Size Report.txt`。
4. 在 DevTools 中分析组件 启动 DevTools 以检查 JSON 分析文件。
dart devtools
* 指导用户在 DevTools 浏览器界面中打开 "App Size Tool",并上传 `*-code-size-analysis_*.json` 文件。
* 使用树状图或支配树来识别大型的包、库或资源。
5. 实施体积缩减策略 将以下策略应用到构建过程和代码库中:
策略 A:分离调试信息并进行混淆 从编译后的二进制文件中提取调试符号,以减少最终产物的大小。
flutter build appbundle --obfuscate --split-debug-info=build/app/outputs/symbols/
策略 B:平台特定的摇树优化 使用 dart:io 的 Platform 检查,确保 Dart AOT 编译器为目标平台移除无法访问的代码。
import 'dart:io';
void initializePlatformSpecificFeatures() {
if (Platform.isWindows) {
// Windows 特定的导入和逻辑
// 在为 Android/iOS 构建时,AOT 编译器会剥离这部分代码
_initWindowsFeatures();
} else if (Platform.isAndroid) {
_initAndroidFeatures();
}
}
6. 验证与修复 应用缩减策略后,重新生成大小分析文件。
flutter build <platform> --analyze-size
请暂停并询问用户: "请将新的 *-code-size-analysis_*.json 文件上传到 DevTools,并使用 'Diff' 标签页与原始文件进行比较。应用大小是否已减少到满足您的要求?"
* _错误状态:_ 如果大小没有减少,请验证 `--split-debug-info` 是否正确应用,以及大型资源 (PNG/JPEG) 是否已被压缩或移除。
flutter run 或标准的 IDE 播放按钮) 来测量应用大小。它们包含调试开销,不能代表生产环境的大小。--split-debug-info 标志时提供一个有效的目录路径。.app 文件的大小;为了获得准确的 iOS 下载大小估算,请始终使用 Xcode App Thinning 大小报告。Platform 检查直接使用 dart:io 常量,以便 AOT 编译器能够准确执行摇树优化。每周安装次数
996
代码仓库
GitHub 星标数
808
首次出现
2026年3月4日
安全审计
安装于
codex962
cursor960
gemini-cli958
github-copilot958
opencode958
kimi-cli957
Analyzes and optimizes Flutter application size by measuring build artifacts, generating size analysis reports, utilizing Dart DevTools for component breakdown, and implementing specific size reduction strategies such as debug info splitting, resource compression, and platform-specific tree-shaking. Assumes a configured Flutter environment and target platform availability.
Use the following decision tree to determine the correct measurement and optimization path:
flutter build <platform> --analyze-size. Proceed to DevTools analysis.flutter build ipa --export-method development and generate an Xcode App Thinning Size Report for accurate download estimates.dart devtools, open the App Size Tool, and upload the generated *-code-size-analysis_*.json file.--split-debug-info, compress assets, and implement Platform checks for aggressive tree-shaking.Determine Target Platform and Baseline STOP AND ASK THE USER: "Which platform (apk, appbundle, ios, linux, macos, windows) are you targeting for size optimization, and do you have a specific size reduction goal?"
Generate Size Analysis File Execute the Flutter build command with the --analyze-size flag to compile Dart with code size usage recording.
# Replace <platform> with apk, appbundle, ios, linux, macos, or windows
flutter build <platform> --analyze-size
Note: This generates a*-code-size-analysis_*.json file in the build/ directory and prints a high-level summary to the terminal.
Generate iOS App Size Report (iOS Only) If targeting iOS, the .app file generated by --analyze-size only evaluates relative size. For an accurate end-user download estimate, generate an Xcode App Size Report.
flutter build ipa --export-method development
build/ios/archive/*.xcarchive) in Xcode.App Thinning Size Report.txt.Analyze Components in DevTools Launch DevTools to inspect the JSON analysis file.
dart devtools
Strategy A: Split Debug Info and Obfuscate Extract debug symbols from the compiled binary to reduce the final artifact size.
flutter build appbundle --obfuscate --split-debug-info=build/app/outputs/symbols/
Strategy B: Platform-Specific Tree Shaking Use dart:io Platform checks to ensure the Dart AOT compiler removes unreachable code for the target platform.
import 'dart:io';
void initializePlatformSpecificFeatures() {
if (Platform.isWindows) {
// Windows-specific imports and logic
// The AOT compiler will strip this out when building for Android/iOS
_initWindowsFeatures();
} else if (Platform.isAndroid) {
_initAndroidFeatures();
}
}
6. Validate and Fix After applying reduction strategies, regenerate the size analysis file.
flutter build <platform> --analyze-size
STOP AND ASK THE USER: "Please upload the new *-code-size-analysis_*.json file to DevTools and compare it with the original using the 'Diff' tab. Did the app size decrease to meet your requirements?"
* _Error State:_ If the size did not decrease, verify that `--split-debug-info` was applied correctly and that large assets (PNG/JPEG) have been compressed or removed.
flutter run or standard IDE play buttons) to measure app size. They contain debugging overhead and are not representative of production sizes.--split-debug-info flag..app file size; always use the Xcode App Thinning Size Report for accurate iOS download size estimates.Platform checks use dart:io constants directly so the AOT compiler can accurately perform tree-shaking.Weekly Installs
996
Repository
GitHub Stars
808
First Seen
Mar 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
codex962
cursor960
gemini-cli958
github-copilot958
opencode958
kimi-cli957
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
102,200 周安装
Grimoire CLI 使用指南:区块链法术编写、验证与执行全流程
940 周安装
Grimoire Uniswap 技能:查询 Uniswap 元数据与生成代币/资金池快照的 CLI 工具
940 周安装
Grimoire Aave 技能:查询 Aave V3 元数据和储备快照的 CLI 工具
941 周安装
Railway CLI 部署指南:使用 railway up 命令快速部署代码到 Railway 平台
942 周安装
n8n Python 代码节点使用指南:在自动化工作流中编写 Python 脚本
943 周安装
Flutter Platform Views 实现指南:Android/iOS/macOS原生视图与Web嵌入教程
943 周安装
*-code-size-analysis_*.json file.Implement Size Reduction Strategies Apply the following strategies to the build process and codebase: