• iOS Flutter Engine源码调试和修改


    iOS Flutter Engine源码调试和修改

    1. 前提:

    1. 已将成功安装deop_tools工具
    2. 已经通过gclient命令同步好flutter engine源码

    2. 步骤:

    进入engine/src目录

    1. 创建flutter engine构建文件

      模式命令生成目录
      host debug./flutter/tools/gn --no-goma --unoptimizedout/host_debug_unopt
      真机debug./flutter/tools/gn --no-goma --ios --unoptimizedout/ios_debug_unopt
      真机release./flutter/tools/gn --no-goma --ios --runtime-mode=releaseout/ios_release
      模拟器debug./flutter/tools/gn --no-goma --ios --simulator --unoptimizedout/ios_debug_sim_unopt
      参数说明:
      --unoptimized  debug模式
      --runtime-mode=release release模式
      --ios iOS平台
      --simulator 模拟器
      
      • 1
      • 2
      • 3
      • 4
      • 5
    2. 生成flutter engine工程文件
      按需执行以下所需的版本类型即可。
      host_debug_unopt是必须要编译的,否则在执行本地引擎时就会报错host_xxx找不到

      // 编译host部分,必须要执行
      ninja -C out/host_debug_unopt
      // 编译模拟器debug版本
      ninja -C out/ios_debug_sim_unopt
      // 编译真机debug版本
      ninja -C out/ios_debug_unopt
      // 编译真机release版本
      ninja -C out/ios_release
      
      • 1
      • 2
      • 3
      • 4
      • 5
      • 6
      • 7
      • 8

      如果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工程到自己创建的工程内

    3. 创建flutter测试工程
      xcode界面中,将要调试模式目录下的flutter_engine工程拖入到测试工程中

      特别注意:在拖动时,要保证flutter_engine工程没有在xcode中打开,否则会出现拖进去后,flutter_engine工程无法展开的问题

    4. 修改Generated.xcconfig中如下配置

      1. 手动修改
        # 如果没有找到对应的配置项,就手动添加
        FLUTTER_FRAMEWORK_DIR=/path/to/engine/src/out/ios_debug_sim_unopt
        FLUTTER_ENGINE=/path/to/engine/src
        LOCAL_ENGINE=ios_debug_sim_unopt
        
        • 1
        • 2
        • 3
        • 4
      2. 自动修改
        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"
              ]
          },
        
        • 1
        • 2
        • 3
        • 4
        • 5
        • 6
        • 7
        • 8
        • 9
        • 10
        • 11
        • 12
    5. 打开FlutterViewController.m文件,就可以下断点了

    6. 修改SDK内的代码,需要重新执行ninja -C 命令去更新产物,然后再重新运行测试工程

    3. 参考资料

    https://tech.qimao.com/zi-ding-yi-flutter-yin-qing-liu-cheng/

  • 相关阅读:
    1024程序员节,今年的秋天比以往来的稍晚了一些
    牛客小白月赛57
    ElasticSearch-Head 数据浏览406问题解决
    Linux:从入门到放弃
    CompletableFuture-电商比价大厂案例
    ORB-SLAM3算法1之Ubuntu18.04+ROS-melodic安装ORB-SLAM3及各种问题解决
    C++基础知识(十四)--- vector容器
    m基于PTS+TR的OFDM系统PAPR联合抑制算法matlab仿真
    Mybatis-plus工具学习笔记(1)---[基本概述,入门案例搭建,通用service接口使用]
    Daily Practice: Codeforces Round #816 (Div. 2)
  • 原文地址:https://blog.csdn.net/clwahaha/article/details/133923560