一、编译Flutter Engine
创建工作目录 engine
添加 depot_tools 到环境变量,并在engine目录下创建.gclient文件
1
2
3
4
5
6
7
8
9
10solutions = [
{
"managed": False,
"name": "src/flutter",
"url": "[email protected]:<your_name_here>/engine.git",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
},
]在engine目录执行
gclient sync
命令同步源码和编译工具链进入
engine/src
目录下,如果是linux平台执行:1
2
3
4sudo ./build/install-build-deps-android.sh
sudo ./build/install-build-deps.sh
sudo ./flutter/build/install-build-deps-linux-desktop.sh如果是mac平台,安装jdk 1.8 和ant:
1
brew install ant
在
engine/src
目录下,生成编译配置文件1
./flutter/tools/gn --android --unoptimized
生成目录
engine/src/out/android_debug_unopt
在
engine/src
目录下,执行编译命令1
ninja -C out/android_debug_unopt
二、如何在mac下编译linux平台的产物?
创建docker镜像,由于需要科学上网,需要自行设置代理
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28FROM ubuntu:16.04
ENV DEPOT_TOOLS_PATH /home/admin/depot_tools
ENV BUILDROOT_PATH /home/admin/buildroot
ENV PATH $PATH:$DEPOT_TOOLS_PATH
# Notes:
# - libx11-dev is used by Flutter for desktop linux (see also install-build-deps-linux-desktop.sh)
# - chrome is used by Flutter for web.
RUN export http_proxy=http://*.*.*.*:*** && \
export https_proxy=http://*.*.*.*:*** && \
export socks_proxy=socks://*.*.*.*:*** && \
apt-get update && \
apt-get install -y sudo wget zip unzip git lsb-release openssh-client curl apt-transport-https libx11-dev software-properties-common build-essential libfreetype6-dev lib32stdc++6 libstdc++6 libpulse0 libglu1-mesa python pkg-config && \
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git $DEPOT_TOOLS_PATH && \
git config --global http.proxy http://*.*.*.*:*** && \
git config --global https.proxy http://*.*.*.*:*** && \
git clone https://github.com/flutter/buildroot.git $BUILDROOT_PATH && \
cd $BUILDROOT_PATH && \
./build/install-build-deps.sh --no-prompt && \
./build/install-build-deps-android.sh --no-prompt && \
apt-get clean
RUN git config --global --unset http.proxy && \
git config --global --unset https.proxy && \
unset http_proxy && \
unset https_proxy && \
unset socks_proxy && \
chmod -R 777 $DEPOT_TOOLS_PATH &&创建image
1
docker build --rm -f "Dockerfile" -t flutter-engine-bulder:latest "."
拉去镜像,如果是本地构建的镜像,则已经存在,如果上传到hub上,则拉去
1
2
3
4
5
6
7docker images | grep flutter-engine-bulder &>/dev/null
if [ $? -ne 0 ]; then
echo "flutter-engine-bulder does not exist,we will docker pull it"
docker pull flutter-engine-bulder:latest
else
echo "flutter-engine-bulder already exists"
fi通过docker 执行gclient sync,将宿主的源码目录engine映射到容器内/home/admin/engine,
1
docker run --rm --privileged=true -v engine:/home/admin/engine -w /home/admin/engine/ flutter-engine-bulder:latest gclient sync
生成配置文件
1
docker run --rm --privileged=true -v engine:/home/admin/engine -w /home/admin/engine/src flutter-engine-bulder:latest ./flutter/tools/gn --android --unoptimized
执行编译
1
docker run --rm --privileged=true -v engine:/home/admin/engine -w /home/admin/engine/src flutter-engine-bulder:latest ninja -C out/android_debug_unopt
docker编译如果很慢,可以自行根据电脑性能设置docker参数:
- 增大docker可使用的cpu核心数
- 增加docker可使用的内存
- 增加docker可使用的交换空间,如果交换空间太小,会出现clang错误
在运行容器时,使用4核cpu编译:
1 | docker run --rm --privileged=true --cpus=4 -v engine:/home/admin/engine -w /home/admin/engine/src flutter-engine-bulder:latest ninja -C out/android_debug_unopt |
参考
https://github.com/flutter/flutter/wiki/Setting-up-the-Engine-development-environment
https://github.com/flutter/flutter/wiki/Compiling-the-engine
https://github.com/flutter/engine/blob/master/ci/docker/build/Dockerfile