linux arm64 编译 flutter engine 及调试

参考:

https://github.com/flutter/flutter/wiki/Compiling-the-engine#compiling-for-android-from-macos-or-linux

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

Debugging the engine · flutter/flutter Wiki (github.com)

Flutter Engine C++ 源码调试初探 | 区长 (fucknmb.com)

Flutter Engine源码调试 | xinbao的书屋 (xinbaos.github.io)

1. 编译需要的代码不是通过 git clone 回来的,而是通过 gclient sync 回来的,所以先安装 gclient

1
2
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
export PATH="$PATH":"/home/alan/source/src/depot_tools"

2. 从 engine 仓库 fork,并配置好 ssh key,注意要 fork 全部分支(取消仅 fork main 分支的勾选)

3. 新建一个目录(engine_flutter),并在里面创建 .gclient 文件,文件内容如下

1
2
3
4
5
6
7
8
9
solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "git@github.com:wild-coffee/engine.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },]

4. 进入到(cd) .gclient 所有目录,执行 gclient sync 同步代码,同步完成后,会把代码下载到配置中的 src/flutter 中

5. 通过访问当前系统安装的 flutter 位置(bin),找到 bin 的上级目录下的此文件获取当前 flutter 的引擎代码完整版本,也可以通过 flutter --version 看引擎的简略版本

1
2
3
which flutter
cd /home/alan/source/src/flutter/bin
cat internal/engine.version

6. 进入到(cd) cd ~/source/src/engine_flutter/src/flutter/ 目录同步代码,如果 reset 失败,可能是在 fork 时,只 fork 了 main 分支

1
2
git reset --hard 74d16627b940bb15e50891f82cad6c3e3465bd6d
git rev-parse HEAD

7. 回到最初建立的目录(engine_flutter),再次同步代码

1
gclient sync --with_branch_heads --with_tags --verbose

8. 进入到 engine_flutter/src 目录,配置编译选项,可查看 out 目录生成的编译配置

1
2
./flutter/tools/gn -h
./flutter/tools/gn --unoptimized --no-goma --no-enable-unittests --runtime-mode debug --target-os linux --linux --linux-cpu arm64 --backtrace

9. 根据在 out 生成的目录名字编译

1
ninja -C out/linux_debug_unopt_arm64

10. 在 ninja 编译期间,请关闭代理设置,如果报以下错误时:

     HttpException: Connection closed before full header was received, uri = http://127.0.0.1:51211/jQ6Nwep21kY=/ws

     请关闭 httpproxy 代理

11. 编译本地引擎的版本

1
2
# 默认编译的 libflutter_linux_gtk.so 是不带符号表的,要使用 out/linux_debug_unopt_arm64/lib.unstripped/ 目录下的 so 文件替换编译后 bundle/lib/ 下的 so 文件
flutter build linux --debug --local-engine=linux_debug_unopt_arm64 --local-engine-host=linux_debug_unopt_arm64 --local-engine-src-path=/home/alan/source/src/engine_flutter/src

12. 配置 visual studio code 代码智能提示

1
2
3
4
5
# 添加 c_cpp_properties.json 文件
使用 Super + Shift + P,选择 C/C++:Edit Configuration 生成 .vscode/c_cpp_properties.json 文件
 
# 修改 c_cpp_properties.json 指定 compile_commands.json 文件位置
"compileCommands": "${workspaceFolder}/../out/linux_debug_unopt_arm64/compile_commands.json"

  

posted @   wild-coffee  阅读(479)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示