获取

源码位于 Github 仓库,但需要使用 gclient 组织工程

https://github.com/flutter/engine

部分依赖的 githook 脚本不支持 python3,需要强制 gclient 使用 python2

set GCLIENT_PY3=0

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

源码拉取后需要切换分支。需要对应 Flutter SDK 版本。在 %FLUTTER_SDK%\bin\internal\engine.version 中查看对应引擎版本。

拉取指定版本引擎配置:

solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "https://github.com/flutter/engine.git@07c1eed46b9d9b58df78566e9b8b2e42e80d3380",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]

执行 gclient sync 同步源码。

编译

参考 https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-windows

切换到 src 目录,使用 .\flutter\tools\gn 脚本创建 ninja 工程。

编译 windowns-x64 release 版本

.\flutter\tools\gn --target-os=win --windows-cpu=x64 --runtime-mode=release

编译 debug 版本,可以使用 --unoptimized 关闭代码优化

.\flutter\tools\gn --target-os=win --windows-cpu=x64 --runtime-mode=debug --unoptimized

默认情况下将使用 clang 作为编译工具链。可以使用 --no-clang 作为参数,在 Windows 平台上改用 MSVC 作为编译工具链。

.\flutter\tools\gn --no-clang

使用 ninja 构建。

ninja -C out\host_release

使用

flutter 命令增加参数 --local-engine-src-path--local-engine