flutter-embedded-linux icon indicating copy to clipboard operation
flutter-embedded-linux copied to clipboard

Simplify Installation of Flutter Engine Library & Cross Compilation

Open Taha-Firoz opened this issue 4 years ago • 2 comments

I've already used flutter pi cross compilation was very straight forward and simple while also providing steps for both Windows and Linux.

Going through the documentation for this project the installation of the flutter engine library is a lot more complex since it requires building it yourself. Compared to how the flutter pi dev has provided pre compiled libraries for arm and arm64 platforms while providing reasonable explanations for each step.

Is there someway we can streamline the cross compilation process for Windows and Linux since that's going to be the case for a majority of embedded systems development use cases.

Taha-Firoz avatar Sep 06 '21 18:09 Taha-Firoz

If you are OK to use a pre-built image, use flutter-elinux. However, if you develop your real product, it would be better to build Flutter Engine and this embedder yourself using your target toolchain/sysroot and use it. See also: Use pre-build image

Does it make sense?

HidenoriMatsubayashi avatar Sep 06 '21 22:09 HidenoriMatsubayashi

Yes it does make sense, I was going through setting up a Yocto build for the first time but since I'm very new to all of this and it seems very very complicated. I would like to help out by making a PR to maybe improve the documentation to make it more approachable for beginners, once I figure out how to make a build myself.

In a very basic way the flutter-pi repository breaks down the entire process in a very simple and approachable way and I hope maybe we can break down the step for this project. I think focusing more on cross compilation is important since that's what any developer will be focusing on and keeping the Raspberry Pi 4 as a reference board is important since it runs ARM 64 bit and is the most accessible to beginners.

Here's a reference to the flutter-pi build + deploy process documentation.

  1. Find out the path to your flutter SDK. For me it's C:\flutter. (I'm on Windows)
  2. Open terminal or commandline and cd into your app directory.
  1. Build the asset bundle.
    flutter build bundle
    
  2. Build the kernel snapshot. (Replace my_app_name with the name of your app)
    C:\flutter\bin\cache\dart-sdk\bin\dart.exe ^
      C:\flutter\bin\cache\dart-sdk\bin\snapshots\frontend_server.dart.snapshot ^
      --sdk-root C:\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk_product ^
      --target=flutter ^
      --aot ^
      --tfa ^
      -Ddart.vm.product=true ^
      --packages .packages ^
      --output-dill build\kernel_snapshot.dill ^
      --verbose ^
      --depfile build\kernel_snapshot.d ^
      package:my_app_name/main.dart
    
  3. Fetch the latest gen_snapshot_linux_x64_release I provide in the engine binaries repo.
  4. The following steps must be executed on a linux x64 machine. If you're on windows, you can use WSL. If you're on macOS, you can use a linux VM.
  5. Build the app.so. If you're building for arm64, you need to omit the --sim-use-hardfp flag.
    gen_snapshot_linux_x64_release \
      --deterministic \
      --snapshot_kind=app-aot-elf \
      --elf=build/flutter_assets/app.so \
      --strip \
      --sim-use-hardfp \
      build/kernel_snapshot.dill
    
  6. Now you can switch to your normal OS again.
  7. Upload the asset bundle and the app.so to your Raspberry Pi.
    rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app
    
    or
    scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app
    
  8. You can now launch the app in release mode using flutter-pi --release /home/pi/my_app

Your project goes into great depth of the entire build process, what components are needed, how those components are built etc. But due to the cross compilation process being much more involved and complicated it can make the entire process unapproachable. Even with the flutter-elinux the quick start or documentation makes cross build seem like an unreasonable decision however it's one of the most important steps for anyone trying to get a build running on any ARM board.

Taha-Firoz avatar Sep 10 '21 10:09 Taha-Firoz

I'll close this issue as there has been no updates for a long time. Thanks.

HidenoriMatsubayashi avatar Aug 06 '23 13:08 HidenoriMatsubayashi