美文网首页flutter学习
Flutter 自定义引擎

Flutter 自定义引擎

作者: 远方竹叶 | 来源:发表于2020-06-29 14:47 被阅读0次

下载引擎代码

工具准备

Chromium 提供的部署工具 depot_tools

git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git

配置工具的环境变量(我放在/opt/目录下,这里面如果你需要放就需要给权限)

添加环境变量.png

下载引擎

  • 新建目录(注意,我们的路径不能有中文,否则后续Down下载的源码会有问题)
mkdir engine
  • 创建gclien文件(我们需要通过gclien下载源码)
touch .gclient
  • 配置文件(确定CommitID 保持一致)
solutions = [
    {
        "managed": False,
        "name": "src/flutter",
        "url": "git@github.com:flutter/engine.git@6bc433c6b6b5b98dcf4cc11aff31cdee90849f32",
        "custom_deps": {},
        "deps_file": "DEPS",
        "safesync_url": "",
    },
]
  • 执行gclient sync (这个操作将会 fetch Flutter 所有的依赖。这里有10G文件,需要点时间,请保持网络!该操作需要翻墙)
gclient sync

关于升级

当我们升级了 Flutter 的 SDK,我们想要升级引擎代码。直接更新 .gclient 文件。

cat $FLUTTER/internal/engine.version
查看版本.png

然后将这个修改到.gclient文件中

修改.png

然后进入src/flutter目录,进行一次 git pull 然后 git reset --hard commitID

git pull
git reset --hard commitID

这个命令就是告诉 Git 我下次下载就下载这个 conmitID 的

Commit.png

回到engine 目录,也就是.gclient文件所在的目录

$gclient sync --with_branch_heads --with_tags --verbose

编译引擎代码

我们先要使用 GN:这是一个生成 Ninja 构建文件的元构建系统,最后我们还是用 Ninja 编译!

GN.png

构建

out 文件夹没编译前是不存在的,需要构建 iOS 设备使用的引擎

#真机debug版本
./gn --ios --unoptimized
#真机release版本(日常开发使用,如果我们要自定义引擎)
./gn --ios --unoptimized --runtime-mode=release
#模拟器版本
./gn --ios --simulator --unoptimized
#主机端(Mac)构建
./gn --unoptimized

构建完成会有四个 Xcode 工程

构建引擎.png

使用 ninja 编译工程(这里也是一个耗时操作,四个操作可以单独编译)

ninja -C host_debug_unopt && ninja -C ios_debug_sim_unopt && ninja -C ios_debug_unopt && ninja -C ios_release_unopt

配置项目代码

项目配置以iOS为例:在iOS工程中,找到Generated.xcconfig文件。在里面添加两个环境变量

FLUTTER_ENGINE=你存放引擎代码的路径/engine/src
#使用的引擎对应版本(这里是iOS-debug模式下-模拟器的版本)
LOCAL_ENGINE=ios_debug_sim_unopt

lipo命令

#可以查看包含的架构
$lipo -info xxx
#拆分架构
$lipo xxx -thin armv7 -output armv7_xxx
#合并多架构
$lipo -create xxx.a xxx.a -output xxx.a

LLDB检查是否含有调试信息

$lldb --file Flutter_arm64
(lldb) target create "Flutter_arm64"
Current executable set to 'Flutter_arm64' (arm64).
(lldb) script lldb.target.module['Flutter_arm64'].GetNumCompileUnits()
1
(lldb)

使用python列出模块的所有编译单元的完整路径

(lldb) target create "Flutter_arm64"
Current executable set to 'Flutter_arm64' (arm64).
(lldb) script
Python Interactive Interpreter. To exit, type 'quit()', 'exit()' or Ctrl-D.
>>> m = lldb.target.module['Flutter_arm64']
>>> for i in range(m.GetNumCompileUnits()):
...     cu = m.GetCompileUnitAtIndex(i).file.fullpath
...     print(cu)
...
None
>>>
exit()

相关文章

网友评论

    本文标题:Flutter 自定义引擎

    本文链接:https://www.haomeiwen.com/subject/ondofktx.html