1. 前提:
- 已将成功安装
deop_tools
工具 - 已经通过
gclient
命令同步好flutter engine
源码
2. 步骤:
-
创建flutter engine构建文件
真机文件:
./flutter/tools/gn --unoptimized --no-goma --ios
模拟器文件:
./flutter/tools/gn --unoptimized --no-goma --simulator
参数说明:debug模式:
--unoptimized
release模式:--runtime-mode=release
真机:--ios
模拟器:--simulator
-
生成flutter engine工程文件
ninja -C out/host_debug_unopt host_debug_unopt是必须要编译的,否则在执行本地引擎时就会报错host_xxx找不到 ninja -C out/ios_debug_sim_unopt ninja -C out/ios_debug_unopt
如果ninja命令执行,出现错误:
depot_tools/ninja.py: Could not find Ninja in the third_party of the current project, nor in your PATH.
说明ninja工具安装有问题,这时候需要回到depot_tools
安装目录,将commit-id
回滚到5a0f43aebe00a947546b8dfc966064b8d1a50a6f
命令执行完成后,就会在
engine/src/out
下产生3个目录,想要调试对应的engine
就拉对应的目录下的flutter_engine
工程到自己创建的工程内 -
创建
flutter
测试工程
在xcode
界面中,将要调试模式目录下的flutter_engine
工程拖入到测试工程中特别注意:在拖动时,要保证
flutter_engine
工程没有在xcode
中打开,否则会出现拖进去后,flutter_engine
工程无法展开的问题 -
修改
Generated.xcconfig
中如下配置- 手动修改
FLUTTER_FRAMEWORK_DIR=/path/to/engine/src/out/ios_debug_sim_unopt FLUTTER_ENGINE=/path/to/engine/src LOCAL_ENGINE=ios_debug_sim_unopt
- 自动修改
在vscode中的launch.json配置文件中新增如下配置,然后跑一下debug
就能同步到Generated.xcconfig
文件中{ "name": "本地engine调试", "type": "dart", "request": "launch", "program": "example/lib/main.dart", "args": [ "--local-engine-src-path", "/path/to/engine/src", "--local-engine", "ios_debug_sim_unopt" ] },
-
打开
FlutterViewController.m
文件,就可以下断点了
3. 参考资料
https://tech.qimao.com/zi-ding-yi-flutter-yin-qing-liu-cheng/
网友评论