Building the Flutter engine for embedded hardware

Mar 1, 2023

Pieter Scholtz

So you want to run flutter on an embedded device? I would not be surprised if you have run into the issue of not being able to find a fitting flutter engine build. No worries you came to the right place.

I am going to make an assumption that most embedded hardware will most likely be either ARM or ARM64 hardware running Linux. If you are doing something different, please do reach out in the comment section.

First one needs to setup the engine development environment. The flutter development wiki does do a pretty good job of this and can be found here , a few tips from me :

  • create the engine directory in the same directory as a peer to your flutter SDK directory. This makes it easier for the flutter SDK to find locally built engine artifacts, more on that here
  • Use a Linux system to build these artifacts.

Next up you need to get to building/compiling the engine. Documentation can be found here.

Examples:

Building the flutter engine for a 32 bit ARM Linux device in debug mode

From the engine/src directory I would run this :

./flutter/tools/gn --no-goma --target-os linux --linux-cpu arm --arm-float-abi hard --embedder-for-target

and then:

ninja -C out/linux_debug_arm

After that has completed, you will find the build artifacts inside out/linux_debug_arm

among these files you will find the following:

libflutter_engine.so is your flutter engine library binary, it looks different on different platforms for example on Linux it will have a .so extension, but on Windows it is a .dll file

icudtl.dat is also important, and is required by embedder API It is important for font rendering.

Building the engine for a 64 bit ARM Linux device in profile mode

./flutter/tools/gn --no-goma --target-os linux --linux-cpu arm64 --runtime-mode profile --embedder-for-target

and then:

ninja -C out/linux_profile_arm64

You will notice that the artifacts look slightly different when building for profile or release mode.

gen_snapshot This is used by the flutter SDK for building flutter applications and not by the embedder.

Engine artifacts version mismatch

If you run into this error when trying to utilize your freshly built artifacts.

Dart Error: Can't load Kernel binary: Invalid kernel binary format
version.

It means that there is a mismatch between the version of engine artifacts you are using and the version of the flutter SDK you used to build the application you are attempting to run.

If you want to build a specific version of the flutter engine, you can change the version by running this command inside the engine directory.

gclient sync --revision=src/flutter@COMMIT_VERSION

You can check if it worked by running the following inside /engine/src/flutter

git log -n 1

Keep in mind that the Flutter SDK you are using indicates the commit version for the engine artifacts that is to be used with it. The engine.version file located at flutter/bin/internal holds the commit hash. Take care to not confuse this directory with the engine/src/flutter directory.

6 comments on "Building the Flutter engine for embedded hardware"

Victor Johns

Mar 9, 2024, 7:12 AM

Hello, I was wondering if you had the commit/version for the flutter engine that you used when doing the ARM(32 bit) build. Seems (??) like the latest flutter engine code does not build with the gn arguments provided. A possible approach to workaround this might be to use a gcc cross compiler instead of clang; I think would present it's own set of issues. Seems a shame that current flutter engine does not build for ARM32 platforms. Quite a few of our clients would prefer to use one of the cheaper ARM platforms ( for instance STM32MP157) instead of the more expensive 64 bit platforms Just thought I would check Best Victor

Pieter Scholtz

Apr 2, 2024, 11:43 AM

Hi Victor, Please have a look at https://github.com/ardera/flutter-ci , it builds the latest binaries for 32 bit arm. Pieter

Andrea Marson

May 4, 2024, 7:52 PM

Hello Pieter, I didn't understand how to cross-build an app for linux-arm target so that it works in tandem with the engine for ARM (no matter whether it is built following your instructions or it is prebuilt). The Flutter SDK does not support such a target: $ flutter build linux -h Build a Linux desktop application. ... --target-platform The target platform for which the app is compiled. [linux-arm64, linux-x64 (default)] Sorry for the naive question, but I am new to the Flutter world. BR, Andrea

Pieter Scholtz

May 28, 2024, 10:50 AM

Hi Andrea , yes the building process is not very obvious at first. I would strongly suggest using https://pub.dev/packages/flutterpi_tool to build the flutter applications , but if you want to know more about it you can have a look here : https://github.com/ardera/flutter-pi?tab=readme-ov-file#building-the-app-old-method-linux-or-windows (the debug build is JIT compiled , and runs anywhere , therefore no need to specify the target platform) Building for profile or release mode requires some attention to the target platform , there is the "old method" but it is a bit tedious : https://github.com/ardera/flutter-pi?tab=readme-ov-file#building-the-appso-for-running-your-app-in-releaseprofile-mode

H Satish Kumar

May 31, 2024, 1:48 AM

Hello, is there any way to built flutter app for 32 bit Linux i.e., x86 arch?

Hannes Winkler

Jun 6, 2024, 12:09 PM

Hey Satish, it's definitely possible, the Dart SDK supports 32-bit x86, but it's not really supported by the Flutter SDK / third party tooling because there's just no users for it. Also chances are, if you can get the flutter app built for x86 32-bit, you'll run into different problems because the overall platform is probably outdated as well (GPU, drivers). But if you do need it, feel free to open an issue here: https://github.com/ardera/flutter-ci

Leave a Comment

Your Email address will not be published

KDAB is committed to ensuring that your privacy is protected.

  • Only the above data is collected about you when you fill out this form.
  • The data will be stored securely.
  • The data will only be used to contact you about possible business together.
  • If we do not engage in business within 3 years, your personal data will be erased from our systems.
  • If you wish for us to erase it earlier, email us at info@kdab.com.

For more information about our Privacy Policy, please read our privacy policy