Building the engine from source - flutter-tizen/flutter-tizen GitHub Wiki

You don't typically need to build the Flutter engine from source (even if you are a contributor to this project). Pre-built engine artifacts are automatically downloaded when you build an app or embedder. The following instructions are only for those who want to customize the Flutter engine internals.

Environment setup

  1. Make sure all required dependencies are available (see Setting up the Engine development environment).

  2. Create an empty directory called engine and cd into it.

  3. Create a .gclient file by running:

    gclient config --name=src/flutter --unmanaged https://github.com/flutter-tizen/engine
    
  4. gclient sync in that directory. This will fetch all the source code that the engine depends on.

    gclient sync --no-history --shallow
    

    Note: This must be run every time the DEPS file is updated.

  5. Change src/flutter's HEAD to track flutter-tizen/engine's default branch. For example, if the current default branch is flutter-3.16.2,

    cd src/flutter
    git checkout flutter-3.16.2
    cd ..
    gclient sync -D --no-history --shallow
    
  6. Open the build/config/compiler/BUILD.gn file and remove the following line.

     if (is_clang && !is_win && !is_mac && !is_ios && !is_wasm) {
    -  ldflags += [ "-Wl,--undefined-version" ]
     }
    
  7. cd into flutter/ci/tizen and run the following commands to build the LLVM toolchain from source.

    # Install prerequisites for build. We use ninja and clang-11 for the build.
    sudo apt update
    sudo apt install git zip build-essential cmake ninja-build clang-11
    
    # Run the build script. This will take a while.
    ./build_llvm.sh
    
    # Install extra packages required by the linker.
    sudo apt install binutils-arm-linux-gnueabi binutils-aarch64-linux-gnu binutils-i686-linux-gnu
    
  8. Also run ./generate_sysroot.py in the same directory to generate Tizen sysroots.

Compile

cd into the buildroot (src) and run the ninja build for your target arch and build mode.

  • tizen-arm-release

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm \
    --target-triple arm-linux-gnueabi \
    --runtime-mode release \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_release_arm flutter_engine_library
    
  • tizen-arm-profile

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm \
    --target-triple arm-linux-gnueabi \
    --runtime-mode profile \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_profile_arm flutter_engine_library
    
  • tizen-arm-debug

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm \
    --target-triple arm-linux-gnueabi \
    --runtime-mode debug \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_debug_arm flutter_engine_library
    
  • tizen-arm64-release

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm64 \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm64 \
    --target-triple aarch64-linux-gnu \
    --runtime-mode release \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_release_arm64 flutter_engine_library
    
  • tizen-arm64-profile

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm64 \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm64 \
    --target-triple aarch64-linux-gnu \
    --runtime-mode profile \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_profile_arm64 flutter_engine_library
    
  • tizen-arm64-debug

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu arm64 \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/arm64 \
    --target-triple aarch64-linux-gnu \
    --runtime-mode debug \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_debug_arm64 flutter_engine_library
    
  • tizen-x86-debug

    flutter/tools/gn \
    --target-os linux \
    --linux-cpu x86 \
    --no-goma \
    --target-toolchain `pwd`/flutter/ci/tizen/toolchains \
    --target-sysroot `pwd`/flutter/ci/tizen/sysroot/x86 \
    --target-triple i686-linux-gnu \
    --runtime-mode debug \
    --enable-fontconfig \
    --disable-desktop-embeddings
    ninja -C out/linux_debug_x86 flutter_engine_library
    

If the build is successful, the output artifacts (libflutter_engine.so) can be found in out/linux_[mode]_[arch].

Using a locally-built engine with the flutter-tizen tool

The flutter-tizen tool accepts three global parameters: local-engine-src-path, local-engine, and local-engine-host. A typical invocation would be:

flutter-tizen run --local-engine-src-path /path/to/engine/src --local-engine linux_debug_arm --local-engine-host host_debug

For details, see https://github.com/flutter/flutter/wiki/The-flutter-tool#using-a-locally-built-engine-with-the-flutter-tool.

You need to replace linux_debug_arm with the actual name for your build. If the kernel compiler fails with an Unexpected Kernel Format Version error, make sure you have set the local-engine parameter correctly (debug/profile/release). For release builds, you may need to run

ninja -C out/linux_release_arm generate_snapshot_bins

to generate the necessary kernel files.

Another option is to manually copy the generated libflutter_engine.so file into the tool's cached artifacts directory (flutter/bin/cache/artifacts/engine), without using the local-engine parameter.

cp out/linux_debug_arm/libflutter_engine.so /path/to/engine/tizen-arm-debug
cp third_party/icu/flutter/icudtl.dat /path/to/engine/tizen-arm-debug