有关编译问题这篇文章讲的很清楚Flutter-Engine-编译指北,本文只是一些自己的简单记录
简要步骤
- 安装depot_tools
- 克隆depot_tools仓库, 获取gclient命令,执行如下:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
- 设置环境变量,编辑 ~/.bashrc或者 ~/.zshrc,添加如下内容:
export PATH=$PATH:/path/to/depot_tools
编译选项
usage: gn [-h] [--unoptimized] [--runtime-mode {debug,profile,release}]
[--dynamic] [--interpreter] [--dart-debug]
[--target-os {android,ios,linux}] [--android]
[--android-cpu {arm,x64,x86,arm64}] [--ios] [--ios-cpu {arm,arm64}]
[--simulator] [--linux-cpu {x64,x86,arm64,arm}]
[--arm-float-abi {hard,soft,softfp}] [--goma] [--no-goma] [--lto]
[--no-lto] [--clang] [--no-clang] [--target-sysroot TARGET_SYSROOT]
[--target-toolchain TARGET_TOOLCHAIN]
[--target-triple TARGET_TRIPLE]
[--toolchain-prefix TOOLCHAIN_PREFIX] [--enable-vulkan]
[--embedder-for-target]
实践
我在编译的时候,本地的flutter环境是1.12.13+hotfix.5 使用file命令查看原有flutter.framework的架构,大小是92.8M
Flutter: Mach-O universal binary with 3 architectures: [x86_64:Mach-O 64-bit dynamically linked shared library x86_64] [arm64]
Flutter (for architecture x86_64): Mach-O 64-bit dynamically linked shared library x86_64
Flutter (for architecture armv7): Mach-O dynamically linked shared library arm_v7
Flutter (for architecture arm64): Mach-O 64-bit dynamically linked shared library arm64
使用如下命令自己打包:
$ ./flutter/tools/gn --ios --simulator
$ ninja -C out/ios_debug_sim
查看架构:
$ file Flutter.framework/Flutter
Flutter.framework/Flutter: Mach-O 64-bit dynamically linked shared library x86_64
大小约为31.7M
$ ./flutter/tools/gn --ios --ios-cpu=arm --runtime-mode=profile
Generating GN files in: out/ios_profile_arm
Generating Xcode projects took 911ms
Done. Made 398 targets from 182 files in 32534ms
$ ./flutter/tools/gn --runtime-mode=profile
Generating GN files in: out/host_profile
Generating Xcode projects took 585ms
Done. Made 579 targets from 204 files in 32341ms