Mobile Development 15 min read

How Does Flutter Compile? A Deep Dive into Its Architecture and Build Process

This article explains Flutter's three‑layer architecture, the differences between JIT and AOT compilation, Dart's various snapshot formats, and the concrete steps and artifacts produced when building Flutter apps for iOS and Android in debug, profile, and release modes.

BaiPing Technology
BaiPing Technology
BaiPing Technology
How Does Flutter Compile? A Deep Dive into Its Architecture and Build Process

Preface

Developers who are proficient with Flutter widgets often know little about how Flutter is compiled and what artifacts are produced.

This article introduces the relevant compilation knowledge.

1. Flutter Architecture Layers

Flutter’s architecture consists of three layers:

1. Framework Layer

Implemented in Dart, it includes:

Material Design (Google) and Cupertino (iOS) widget styles.

Basic widgets such as text, image, button.

Rendering, animation, drawing, gesture widgets.

Core classes and methods from the Flutter package and the sky_engine packages (io, async, ui).

2. Engine Layer

Implemented in C++, it includes:

Skia – an open‑source 2D graphics library.

Dart runtime, garbage collection, and JIT support in debug mode; AOT compilation to native ARM code in release/profile mode.

Text rendering pipeline: libtxt (font selection), HarfBuzz (glyph shaping), and Skia (GPU backend) – using FreeType on Android/Fuchsia and CoreGraphics on iOS.

3. Embedder Layer

The embedder integrates Flutter into each platform, handling surface setup, thread configuration, and plugins. The platform only provides a canvas; all rendering logic lives inside Flutter, ensuring cross‑platform consistency.

2. Flutter Compilation Modes

Compilation modes describe how source code is turned into machine code and executed.

Generally there are two categories:

JIT

(Just‑In‑Time) and

AOT

(Ahead‑Of‑Time).

1. JIT

Source is compiled at runtime, allowing dynamic code delivery but causing slower startup.

2. AOT

Source is compiled ahead of time into native binaries, giving fast startup and execution at the cost of larger binaries and no dynamic updates on restrictive platforms.

3. Dart Compilation Modes

1. Dart VM

The Dart VM can interpret code, JIT‑compile it, or use an AOT pipeline to produce a pre‑compiled runtime without a compiler.

2. Dart Snapshot Types

Dart can produce several snapshot formats:

Script : plain JIT execution of .dart files.

Kernel Snapshots : binary AST (platform‑independent).

JIT Application Snapshots : parsed classes and data, faster but architecture‑specific.

AOT Application Snapshots : ahead‑of‑time compiled binaries for a specific platform.

4. Flutter Compilation Modes per Development Phase

Flutter supports three build modes:

Debug : Uses Dart JIT, enables hot‑reload, suitable for rapid development on devices and emulators.

Release : Uses Dart AOT, disables debugging, optimizes startup speed, execution speed, and binary size; hot‑reload is unavailable.

Profile : Similar to Release but retains some profiling tools for performance analysis on real devices.

3. Flutter Build Process

1. flutter run

Running flutter run without arguments defaults to Debug mode; adding -release switches to Release mode.

The command orchestrates several sub‑commands located in flutter/packages/flutter_tools:

flutter build apk (via Gradle)

flutter build aot (produces AOT artifacts)

frontend_server (generates kernel files)

gen_snapshot (converts Dart kernel to AOT binaries)

flutter build bundle (places assets into flutter_assets)

2. frontend_server

Executes frontend_server.dart.snapshot to transform Dart code into an app.dill kernel file.

3. gen_snapshot

Generates AOT machine code from the kernel. The command differs for Android and iOS.

4. Flutter Build Artifacts

iOS – Release

Structure similar to a native app; App.framework and Flutter.framework contain resources in flutter_assets.

Android – Release

Similar to native app; flutter_assets holds Flutter resources, and libapp.so and libflutter.so are added.

iOS – Debug

Additional files: isolate_snapshot_data, kernel_blob.bin, vm_snapshot_data. Binary size is ~33 KB (vs 8.5 MB in release).

Android – Debug

Similar to iOS debug: flutter_assets contains the three snapshot files; libapp.so is omitted.

Artifact Summary

Flutter apps contain two libraries: one compiled from Dart code, the other from the engine.

Debug mode generates three temporary files for hot‑reload; release mode merges them into the app library. isolate_snapshot_data speeds up isolate startup (non‑business code). kernel_blob.bin holds the compiled business code. vm_snapshot_data accelerates Dart VM startup (non‑business code).

Original resources and Flutter resources are isolated.

5. What Can We Do?

Understanding Flutter’s compilation allows us to:

Optimize artifact size based on platform characteristics.

Split modules, speed up compilation, and reduce packaging time.

Explore dynamic Flutter features and Flutter for Web.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DARTFlutterCompilation
BaiPing Technology
Written by

BaiPing Technology

Official account of the BaiPing app technology team. Dedicated to enhancing human productivity through technology. | DRINK FOR FUN!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.