Skip to content

Creating Ahead of Time (AOT) image

Joel Winarske edited this page Dec 10, 2021 · 3 revisions

Creating Ahead of Time (AOT) image

Dart VM version in SDK needs to match the one implemented in Flutter Engine.

Once you have a Flutter Engine with matching Dart VM to Flutter SDK, then you can do this:

        ${FLUTTER_SDK}/bin/cache/dart-sdk/bin/dart \
        --verbose \
        --disable-analytics \
        --disable-dart-dev ${FLUTTER_SDK}/bin/cache/artifacts/engine/linux-x64/frontend_server.dart.snapshot \
        --sdk-root ${FLUTTER_SDK}/bin/cache/artifacts/engine/common/flutter_patched_sdk_product/ \
        --target=flutter \
        --no-print-incremental-dependencies \
        -Ddart.vm.profile=false -Ddart.vm.product=true \
        --aot --tfa \
        --packages .dart_tool/package_config.json \
        --output-dill .dart_tool/flutter_build/*/app.dill \
        --depfile .dart_tool/flutter_build/*/kernel_snapshot.d \
        package:${PUBSPEC_APPNAME}/main.dart

        ${ENGINE_SDK}/clang_x64/gen_snapshot \
        --snapshot_kind=app-aot-elf \
        --elf=libapp.so \
        --strip \
        .dart_tool/flutter_build/*/app.dill

gen_snapshot is machine architecture dependent. You cannot use any gen_snapshot. If you are targeting desktop build, gen_snapshot (Linux x86_64) comes from Flutter SDK. If you are performing cross compilation using Yocto (meta-flutter), then gen_snapshot is available in /usr/share/flutter/engine_sdk.zip.

References

https://github.com/meta-flutter/meta-flutter/blob/honister/classes/flutter-app.bbclass#L46

https://github.com/meta-flutter/meta-flutter/blob/honister/recipes-graphics/flutter-engine/flutter-engine.inc#L208

Clone this wiki locally