Flutter Architecture, Build Process, and Customization Guide
The guide explains Flutter’s three‑layer architecture (Framework, Engine, Embedder), Dart compilation modes, iOS and Android build pipelines, project layout, and how to customize or rebuild the Engine, manage engine versions, and extend the framework for future native integration.
Background : This article provides a comprehensive overview of Flutter, covering its design, language (Dart), three‑layer architecture (Framework, Engine, Embedder), compilation process, and how it integrates with native Android/iOS projects. It uses a simple hello_flutter example to illustrate concepts.
Flutter Architecture : The Framework is written in Dart and includes Material and Cupertino widgets, rendering, animation, and gesture handling. The Engine, implemented in C++, contains Skia for graphics, the Dart runtime (JIT for Debug, AOT for Release/Profile), and text rendering (libtxt, HarfBuzz, FreeType/CoreGraphics). The Embedder embeds Flutter into a host platform, providing a canvas and handling threads and plugins.
Project Structure : A typical Flutter project contains ios (CocoaPods), android (Gradle), and lib (Dart) directories. The pubspec.yaml and pubspec.lock files manage Dart dependencies similarly to Podfile in iOS.
Build Modes :
Debug – Dart runs in JIT mode, enabling hot‑reload, assertions, and debugging services.
Release – Dart is AOT‑compiled to native ARM code; JIT is omitted, resulting in smaller binaries and faster startup.
Profile – Like Release but retains profiling hooks.
iOS Compilation (Release) :
The Dart code is compiled by gen_snapshot (tree‑shaking enabled) into assembly, then linked with xcrun to produce App.framework . The final app bundle contains App.framework , Flutter.framework , and the flutter_assets directory.
iOS Compilation (Debug) :
In Debug, Flutter.framework includes JIT support, while App.framework contains only a small API; the actual Dart bytecode resides in snapshot_blob.bin .
Android Compilation (Release) :
The Dart code is compiled to ARM snapshots ( vm/isolate_snapshot_data and vm/isolate_snapshot_instructions ) packaged inside the APK. flutter.jar provides the Engine (native libflutter.so ) and Embedder.
Customization & Optimization :
Modifications are usually performed in the flutter_tools package and the Engine source. Example steps include:
if [[ ! -f "SNAPSHOT_PATH" ]] || [[ ! -s "STAMP_PATH" ]] || [[ "$(cat "STAMP_PATH")" != "revision" ]]; then
# rebuild flutter tools
fiChanging the Android target ABI to armeabi :
# In flutter.gradle
android {
defaultConfig {
ndk {
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
}
}
}Switching the default launch activity:
# In flutter_tools source
if [[ "$FLUTTER_BUILD_MODE" == "release" ]]; then
# set launchable activity
fiBuilding a custom Engine for iOS armv7:
./flutter/tools/gn --runtime-mode=release --ios-cpu=arm
ninja -C out/ios_release_armBuilding a custom Engine for Android arm:
./flutter/tools/gn --runtime-mode=debug --android-cpu=arm
ninja -C out/android_debugTo debug the Engine source, use an unoptimized debug build:
./flutter/tools/gn --runtime-mode=debug --unoptimized --ios-cpu=arm64
ninja -C out/ios_debug_unoptEngine Version Management : The Flutter beta version pins an Engine commit (e.g., 09d05a389 ). To apply upstream fixes, create a branch from that commit, run gclient sync , and cherry‑pick desired commits.
Future Topics listed include Embedder rendering/event handling, Dart debugging inside the Engine, progressive migration of native code to Flutter, and private Pub repository setup.
Contact : The article ends with a call for contributors and a QR code for the “闲鱼技术” public account.
Xianyu Technology
Official account of the Xianyu technology team
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.