-
Notifications
You must be signed in to change notification settings - Fork 128
Building Flutter apps
This page describes how to build Fluter apps.
You need to install flutter-elinux. See: flutter elinux install
Here introduce how to build the flutter sample app.
Note that you need to build Flutter apps in the same mode(release/debug) libflutter_engine.so
was built. It means you need to build Flutter apps in the release mode if you use libflutter_engine.so
was built in release mode.
This is the method when the build machine and the target machine are the same. (x64 targets on x64 hosts / for Arm64 targets on Arm64 hosts)
$ flutter-elinux create sample
$ cd sample
$ flutter-elinux build elinux
The build result: build/elinux/{cpu-arch}/release/bundle/
$ flutter-elinux create sample
$ cd sample
$ flutter-elinux build elinux --debug
The build result: build/elinux/{cpu-arch}/debug/bundle/
Also, You can do the following steps on both x64 and arm64 hosts. In debug mode, the Flutter bundle artifacts are not architecturally different between x64 and arm64.
$ flutter-elinux build bundle --asset-dir=./bundle/data/flutter_assets
$ cp <path_to_flutter_sdk_install>/bin/cache/artifacts/engine/elinux-common/icu/icudtl.dat ./bundle/data
See: Cross-building from x64 to arm64
You need to clang_x64/gen_snapshot
is one of the artifacts of the Flutter engine you built. See: Building Flutter Engine
$ flutter-elinux create sample
$ cd sample
# Path to Flutter SDK
$ export FLUTTER_SDK=/opt/flutter-elinux/flutter
# Package name of the build target Flutter app
$ export APP_PACKAGE_NAME=sample
# The build data.
$ export RESULT_DIR=build/linux-embedded-arm64
$ export BUILD_MODE=release
$ mkdir -p .dart_tool/flutter_build/flutter-embedded-linux
$ mkdir -p ${RESULT_DIR}/${BUILD_MODE}/bundle/lib/
$ mkdir -p ${RESULT_DIR}/${BUILD_MODE}/bundle/data/
# You need to use `gen_snapshot` for cross-building
$ mkdir -p ${FLUTTER_SDK}/bin/cache/artifacts/engine/linux-arm64-release/clang_x64
$ cp <path_to_your_working_directory_to_build_engine>/src/out/linux_release_arm64/clang_x64/gen_snapshot \
${FLUTTER_SDK}/bin/cache/artifacts/engine/linux-arm64-release/clang_x64/gen_snapshot
# Build Flutter assets.
$ flutter build bundle --asset-dir=${RESULT_DIR}/${BUILD_MODE}/bundle/data/flutter_assets
$ cp ${FLUTTER_SDK}/bin/cache/artifacts/engine/linux-x64/icudtl.dat \
${RESULT_DIR}/${BUILD_MODE}/bundle/data/
# Build kernel_snapshot.
$ ${FLUTTER_SDK}/bin/cache/dart-sdk/bin/dart \
--verbose \
--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/flutter-embedded-linux/app.dill \
--depfile .dart_tool/flutter_build/flutter-embedded-linux/kernel_snapshot.d \
package:${APP_PACKAGE_NAME}/main.dart
# Build AOT image.
$ ${FLUTTER_SDK}/bin/cache/artifacts/engine/linux-arm64-release/clang_x64/gen_snapshot \
--deterministic \
--snapshot_kind=app-aot-elf \
--elf=.dart_tool/flutter_build/flutter-embedded-linux/libapp.so \
--strip \
.dart_tool/flutter_build/flutter-embedded-linux/app.dill
$ cp .dart_tool/flutter_build/flutter-embedded-linux/libapp.so ${RESULT_DIR}/${BUILD_MODE}/bundle/lib/
The build result: build/linux-embedded-arm64/release/bundle