Build Flutter engine for Linux ARM64

HW: Hardkernel ODROID-N2, ODROID-VU7A+ (https://www.hardkernel.com/product/)

OS: Ubuntu disco minimal 20191228 (http://ppa.linuxfactory.or.kr/images/raw/arm64/disco/)



caution

Make sure the command ran successfully before running the next command!!

Host(Linux x86_64)

sudo apt-get update \
&& sudo apt install -y git gcc build-essential make \
subversion texinfo bison flex cmake ninja-build python3
&& sudo apt autoremove -y
mkdir -p $HOME/flutter-engine/sdk/toolchain \
&& mkdir -p $HOME/flutter-engine/sdk/sysroot \
&& mkdir -p $HOME/flutter-engine/engine

sysroot

It may vary depending on various conditions. If symbolic links are broken, various errors will occur when you follow the steps below.

Most of the errors that occurred to me were for this reason.

Target(Linux ARM64)

Connect the SD card or eMMC with OS to your SBC.

sudo apt update \
&& sudo apt install -y build-essential libgtk-3-dev libgles2-mesa-dev \
pkg-config symlinks \
&& sudo apt autoremove -y
sudo symlinks -crs /*

Host(Linux x86_64)

Connect the SD card or eMMC to your computer. Change directory to mounted directory.

cd /media/*/rootfs
sudo rsync -rlpv lib usr $HOME/flutter-engine/sdk/sysroot \
&& sync

When I built all successfully, the directory structure is shown below. Since / (root) is copied to $HOME/flutter-engine/sdk/sysroot, setting a symbolic link path to an absolute path can break symbolic links.

$HOME/flutter-engine/sdk/sysroot
├── lib -> usr/lib
└── usr
├── include
│ └── ...
└── lib
├── aarch64-linux-gnu
│   ├── crt1.o
│   ├── crti.o
│   ├── crtn.o
│   ├── ld-2.29.so
│   ├── ld-linux-aarch64.so.1 -> ld-2.29.so
│   ├── libc-2.29.so
│   ├── libc_nonshared.a
│   ├── libc.so
│   ├── libc.so.6 -> libc-2.29.so
│   ├── libdl-2.29.so
│   ├── libdl.so -> ../../../lib/aarch64-linux-gnu/libdl.so.2
│   ├── libdl.so.2 -> libdl-2.29.so
│   ├── libgcc_s.so.1
│   ├── libm-2.29.so
│   ├── libm.so -> libm.so.6
│   ├── libm.so.6 -> libm-2.29.so
│   ├── libpthread-2.29.so
│   ├── libpthread.so -> ../../../lib/aarch64-linux-gnu/libpthread.so.0
│   ├── libpthread.so.0 -> libpthread-2.29.so
│   ├── librt-2.29.so
│   ├── librt.so -> ../../../lib/aarch64-linux-gnu/librt.so.1
│   ├── librt.so.1 -> librt-2.29.so
│   ├── libstdc++.so.6 -> libstdc++.so.6.0.26
│   └── libstdc++.so.6.0.26
└── gcc
└── aarch64-linux-gnu
└── 8
├── crtbegin.o
├── crtbeginS.o
├── crtend.o
├── crtendS.o
├── libgcc.a
├── libgcc_s.so -> ../../../aarch64-linux-gnu/libgcc_s.so.1
└── libstdc++.so -> ../../../aarch64-linux-gnu/libstdc++.so.6

Clang installation

clang and LLVM

git clone --branch=llvmorg-10.0.0 --depth=1 https://github.com/llvm/llvm-project.git $HOME/flutter-engine/llvm-project
cd $HOME/flutter-engine/llvm-project \
&& [ -d build_llvm ] && sudo rm -r build_llvm ;\
mkdir build_llvm && cd build_llvm \
&& cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS=clang \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DCMAKE_CROSSCOMPILING=True \
-DLLVM_DEFAULT_TARGET_TRIPLE=aarch64-linux-gnu \
-DLLVM_TARGET_ARCH=AArch64 \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
../llvm \
&& ninja \
&& sudo ninja install

binutils-gdb

git clone --depth=1 git://sourceware.org/git/binutils-gdb.git $HOME/flutter-engine/binutils-gdb
cd $HOME/flutter-engine/binutils-gdb \
&& ./configure --prefix="$HOME/flutter-engine/sdk/toolchain" \
--enable-gold \
--enable-ld \
--target=aarch64-linux-gnu \
&& make -j$(expr $(expr $(nproc) \* 6) \/ 5) \
&& sudo make install
sudo cp -ap $HOME/flutter-engine/sdk/toolchain/bin/aarch64-linux-gnu-* \
$HOME/flutter-engine/sdk/sysroot/usr/bin/

libcxxabi and libcxx

cd $HOME/flutter-engine/llvm-project \
&& [ -d build_libcxxabi ] && sudo rm -r build_libcxxabi ;\
mkdir build_libcxxabi && cd build_libcxxabi \
&& cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=True \
-DCMAKE_SYSROOT=$HOME/flutter-engine/sdk/sysroot \
-DLIBCXX_ENABLE_SHARED=False \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=AArch64 \
-DCMAKE_C_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang \
-DCMAKE_CXX_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang++ \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
-DLIBCXX_ENABLE_EXCEPTIONS=False \
../libcxxabi \
&& ninja \
&& sudo ninja install
cd $HOME/flutter-engine/llvm-project \
&& [ -d build_libcxx ] && sudo rm -r build_libcxx ;\
mkdir build_libcxx && cd build_libcxx \
&& cmake -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_CROSSCOMPILING=True \
-DCMAKE_SYSROOT=$HOME/flutter-engine/sdk/sysroot \
-DLIBCXX_ENABLE_SHARED=False \
-DCMAKE_INSTALL_PREFIX=$HOME/flutter-engine/sdk/toolchain \
-DCMAKE_SYSTEM_NAME=Linux \
-DCMAKE_SYSTEM_PROCESSOR=AArch64 \
-DCMAKE_C_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang \
-DCMAKE_CXX_COMPILER=$HOME/flutter-engine/sdk/toolchain/bin/clang++ \
-DLLVM_TARGETS_TO_BUILD=AArch64 \
-DLIBCXX_ENABLE_EXCEPTIONS=False \
-DLIBCXX_ENABLE_RTTI=False \
-DLIBCXX_CXX_ABI=libcxxabi \
-DLIBCXX_CXX_ABI_INCLUDE_PATHS=$HOME/flutter-engine/llvm-project/libcxxabi/include \
-DLIBCXX_CXX_ABI_LIBRARY_PATH=$HOME/flutter-engine/sdk/toolchain/lib \
-DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=True \
../libcxx \
&& ninja \
&& sudo ninja install

depot_tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $HOME/flutter-engine/depot_tools
export PATH=$PATH:$HOME/flutter-engine/depot_tools

flutter-engine

Ref: https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment

After reading the Ref above, follow flutter-engine part.

echo 'solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "git@github.com:hhk7734/engine.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]' >> $HOME/flutter-engine/engine/.gclient \
&& cd $HOME/flutter-engine/engine \
&& gclient sync
cd $HOME/flutter-engine/engine/src/flutter \
&& git remote add upstream git@github.com:flutter/engine.git
cd $HOME/flutter-engine/engine/src \
&& sudo ./build/install-build-deps-android.sh
sudo ./build/install-build-deps.sh
sudo ./flutter/build/install-build-deps-linux-desktop.sh
cd $HOME/flutter-engine/engine/src/flutter \
&& git pull upstream master && gclient sync
cd $HOME/flutter-engine/engine/src \
&& [ -d out/linux_debug_arm64 ] && sudo rm -r out/linux_debug_arm64 ;\
./flutter/tools/gn \
--clang \
--target-sysroot $HOME/flutter-engine/sdk/sysroot \
--target-toolchain $HOME/flutter-engine/sdk/toolchain \
--target-triple aarch64-linux-gnu \
--linux-cpu arm64 \
--runtime-mode debug \
--embedder-for-target \
--no-lto \
--target-os linux \
--arm-float-abi hard
ninja -C out/linux_debug_arm64
cd $HOME/flutter-engine/engine/src/out/linux_debug_arm64

Copy flutter_embedder.h, libflutter_engine.so, libflutter_linux_gtk.so, icudtl.dat to Target.

scp flutter_embedder.h libflutter_engine.so libflutter_linux_gtk.so icudtl.dat \
<user>@<ip>:~

Target(Linux ARM64)

cd \
&& sudo mv libflutter_engine.so libflutter_linux_gtk.so icudtl.dat /usr/lib \
&& sudo mv flutter_embedder.h /usr/include
sudo apt install -y git clang pkg-config \
libglvnd-dev libgl1-mesa-dev libgles2-mesa-dev libegl-mesa0 \
libdrm-dev libgbm-dev \
gpiod libgpiod-dev
sudo apt install ttf-mscorefonts-installer fontconfig \
&& sudo fc-cache

flutter-arm

git clone https://github.com/hhk7734/flutter-arm.git \
&& cd flutter-arm \
&& make
sudo make install

Example

Host

cd $HOME/development/flutter/examples/flutter_gallery
flutter build bundle
scp -r build/flutter_assets <user>@<ip>:~

Target

sudo flutter-arm -i"/dev/input/event*" flutter_assets
Last updated on