2021-12-14 flutter产物
- engine产物:Flutter.framework
- lib/main.dart产物:App.framework
本文以flutter.2.2.2为例,打包release app和debug run真机,探究。
1、 Flutter.framework
engine产物,存放路径:
/Volumes/huc/opt/fvm/versions/2.2.0/bin/cache/artifacts/engine/ios

Flutter.framework:

以ios-arm64_armv7为例:
大小差别:
Flutter
debug: 69.5mb
release: 482.3mb
profile: 36.3mb
2、 App.framework
release: 16kb-> 16.5Mb
- App:12.7M
- 其他:3.8Mb
debug: 16kb-> 61.3Mb
- App:52KB,
- isolate_snapshot_data:4.2MB
- kernel_blob.bin:53.3Mb
- vm_snapshot_data:11KB
- 其他:和debug的一样就是资源图片等:3.8Mb
文件说明
- App 库文件
- Info.plist
- flutter_assets 资源目录
- isolate_snapshot_data debug模式下用于加速isolate启动
- kernel_blob.bin debug模式下Dart代码产物
- vm_snapshot_data debug模式下用于加速dart vm启动

(1)、 第一步
podhelper.rb执行:App.framework App 16kb
(在pod install之前通过flutter pub get得到的还没有App.framework)
编译核心代码:
debug 和release 一样:
FileUtils.mkdir_p(app_framework_dir)
`echo "static const int Moo = 88;"
| xcrun clang -x c -dynamiclib -o "#{app_framework_dylib}" -`
路径: flutter项目的.ios目录下:
App.framework大小16kb:

里面就只有一个App,同样为16kb: 就是给App包了framework一个目录壳子

(2)、第二步
flutter_export_environment.sh执行后
核心代码:
/opt/fvm/versions/2.2.0/bin/flutter
assemble
-dTargetFile=lib/main.dart
-dBuildMode=debug
-dIosArchs=arm64
debug_ios_bundle_flutter_assets
release产物:
经过这一步:
App.framework 大小为16.5MB

App.framework:看看里面
路径:在buildRelease-iphoneos目录下面(不是在flutter项目那边的.ios目录下)
App为12.7Mb

其他的是flutter_assets

packages目录下是依赖库的assets

debug产物:
App.framework 61.3Mb
路径:
/Users/huchu/Library/Developer/Xcode/DerivedData/HouseCommercialCube-haouxiieutwwizfrzseumgibdjxb/Build/Products/Debug-iphoneos

里面App大小为52K

出了assets以外多了3个文件

完整命令:
release的完整编译指令:
/opt/fvm/versions/2.2.0/bin/flutter
--verbose
assemble
--no-version-check
--output=/Volumes/huc/houseCommercial/HouseCommercialCube/build/Build/Intermediates.noindex/ArchiveIntermediates/HouseCommercialCube/BuildProductsPath/Release-iphoneos/
-dTargetPlatform=ios
-dTargetFile=lib/main.dart
-dBuildMode=release
-dIosArchs=arm64
-dSdkRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk -dSplitDebugInfo=
-dTreeShakeIcons=false
-dTrackWidgetCreation=false
-dDartObfuscation=false
-dEnableBitcode=
-dCodesignIdentity=5E7BAF216A1F5452AF29BD94397B31DC4029A5C6
--ExtraGenSnapshotOptions=
--DartDefines=
--ExtraFrontEndOptions=
release_ios_bundle_flutter_assets
debug完整编译指令:
/opt/fvm/versions/2.2.0/bin/flutter
--verbose
assemble
--no-version-check
--output=/Users/huchu/Library/Developer/Xcode/DerivedData/HouseCommercialCube-haouxiieutwwizfrzseumgibdjxb/Build/Products/Debug-iphoneos/
-dTargetPlatform=ios
-dTargetFile=lib/main.dart
-dBuildMode=debug
-dIosArchs=arm64
-dSdkRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk -dSplitDebugInfo=
-dTreeShakeIcons=false
-dTrackWidgetCreation=false
-dDartObfuscation=false
-dEnableBitcode=
-dCodesignIdentity=FD1A800911570C03E014A5628E4B5F87C416FC06
--ExtraGenSnapshotOptions=
--DartDefines=
--ExtraFrontEndOptions= debug_ios_bundle_flutter_assets