-
Notifications
You must be signed in to change notification settings - Fork 131
Building Flutter Engine from source
See also:
You can also download a specific libflutter_engine.so
(stable) version from https://github.com/sony/flutter-embedded-linux/releases/latest without building yourself.
However, please note that Flutter Engine is using many third-party software libraries. So you need to build the Flutter Engine yourself by following the steps below if you want to check all software licenses.
$ sudo apt install g++-multilib git python3 curl
$ git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
$ export PATH=$PATH:$(pwd)/depot_tools
Python 2 is required to build. If you default installation is Python 3 you could workaround this by using virtualenv:
$ virtualenv .env -p python2
$ source .env/bin/activate
See also: https://github.com/dart-lang/sdk/wiki/Building#python-2
It isn't recommended using the latest version unless you want to build the Engine.
solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "https://github.com/flutter/engine.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
"custom_vars" : {
"download_android_deps" : False,
"download_windows_deps" : False,
},
},
]
You can check the current engine version (commit-id / SHA):
See also: https://github.com/flutter/flutter/wiki/Flutter-build-release-channels
You can also get the engine version from ${path_to_flutter_sdk_install}/flutter/bin/internal/engine.version
of the Flutter SDK which you are currently using.
solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "https://github.com/flutter/engine.git@FLUTTER_ENGINE",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
"custom_vars" : {
"download_android_deps" : False,
"download_windows_deps" : False,
},
},
]
Note: Replace FLUTTER_ENGINE
with a version you want to use.
$ gclient sync
$ cd src
$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode debug --unoptimized \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/linux_debug_unopt_arm64
$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode profile --no-lto \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/linux_profile_arm64
$ ./flutter/tools/gn --target-os linux --linux-cpu arm64 --runtime-mode release \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/linux_release_arm64
$ ./flutter/tools/gn --runtime-mode debug --unoptimized \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/host_debug_unopt
$ ./flutter/tools/gn --runtime-mode profile --no-lto \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/host_profile
$ ./flutter/tools/gn --runtime-mode release \
--embedder-for-target --disable-desktop-embeddings --no-build-embedder-examples \
--enable-fontconfig
$ ninja -C out/host_release
$ cp ./out/${path to your selected target and mode}/libflutter_engine.so <path_to_cmake_build_directory>
You need to install libflutter_engine.so
in <path_to_cmake_build_directory>
to build. But you can switch quickly between debug / profile / release modes for the Flutter app without replacing libflutter_engine.so
by using LD_LIBRARY_PATH
when you run the Flutter app.
$ LD_LIBRARY_PATH=<path_to_engine> ./flutter-client <path_to_flutter_project_bundle>
# e.g. Run in debug mode
$ LD_LIBRARY_PATH=/usr/lib/flutter_engine/debug/ ./flutter-client ./sample/build/linux/x64/debug/bundle
# e.g. Run in profile mode
$ LD_LIBRARY_PATH=/usr/lib/flutter_engine/profile/ ./flutter-client ./sample/build/linux/x64/profile/bundle
# e.g. Run in release mode
$ LD_LIBRARY_PATH=/usr/lib/flutter_engine/release/ ./flutter-client ./sample/build/linux/x64/release/bundle
If you want to cross-build for arm64 on x64, you need to use out/linux_*_arm64/clang_x64/gen_snapshot
later. See also: https://github.com/sony/flutter-embedded-linux/wiki/Building-Flutter-apps#cross-build-for-arm64-targets-on-x64-hosts