首页
社区
课程
招聘
[原创]手把手教大家如何编译flutter的引擎文件libflutter.so(重置版本)
2022-5-17 17:11 15627

[原创]手把手教大家如何编译flutter的引擎文件libflutter.so(重置版本)

2022-5-17 17:11
15627

前言

要想完全的了解flutter引擎的内容,需要自行编译做调试跟进。

 

核心参考 https://github.com/Impact-I/reFlutter/blob/main/.github/workflows/main.yml

 

这个 github action 配置文件

 

为了这次编译我完全开了一个新的ubuntu18的虚拟机。下面开干。

配置代理

depot_tools 安装配置

depot_tools 谷歌的包管理工具,可以管理多个git项目。重点就是可以断点续传,避免拉一半消失。

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

配置环境变量使gclient命令生效

1
gedit /etc/profile

底部新增一行

1
export PATH="$PATH:/home/nizz/work_space/flutter/depot_tools"

配置生效

1
source /etc/profile

下拉flutter engine仓库

这一步我们使用gclient来拉取仓库

 

新建文件夹

1
2
mkdir engine_compile
cd engine_compile

新建配置文件填写gclient配置

1
2
touch .gclient
gedit .gclient

写入配置

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

方便同步 可以fork一份到自己仓库 配置ssh密钥

 

参考 https://blog.csdn.net/qq_36275734/article/details/78877851

 

修改前面的git仓库路径为自己的

 

开始同步

1
gclient sync

需要等很久 打开网络流量监控看下

 

切换源码分支

同步完成切换分支 先去看本地的flutter版本

 

你的flutter环境下的 /flutter/bin/internal/engine.version可以找到

 

比如我的 57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab

 

https://github.com/flutter/engine/tree/57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab

1
cd src/flutter
1
git reset --hard 57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
1
2
3
nizz@ubuntu:~/work_space/flutter/engine_compile/src/flutter$ git reset --hard 57d3bac3dd5cb5b0e464ab70e7bc8a0d8cf083ab
Checking out files: 100% (1993/1993), done.
HEAD is now at 57d3bac3dd Adds a gn script flag to select mallinfo2 when building the Dart VM (#32187) (#32221)

查看当前commitid

1
git rev-parse HEAD

确认开始同步

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

又是漫长的等待同步完成

开始编译

1
apt-get install ninja-build

编译预配置

 

只编译安卓

1
./flutter/tools/gn --android --unoptimized
1
2
3
4
5
nizz@ubuntu:~/work_space/flutter/engine_compile/src$ ./flutter/tools/gn --android --unoptimized
GOMA usage was specified but can't be found, falling back to local builds. Set the GOMA_DIR environment variable to fix GOMA.
Generating GN files in: out/android_debug_unopt
Generating compile_commands took 56ms
Done. Made 582 targets from 223 files in 580ms

具体的编译参数看官方文档

 

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

 

开始编译 自行输出目录 是前面创建的输出目录

1
ninja -C out/android_debug_unopt

等待成功即可。

1
2
3
4
5
6
7
8
9
10
nizz@ubuntu:~/work_space/flutter/engine_compile/src$ sudo ninja -C out/android_debug_unopt
ninja: Entering directory `out/android_debug_unopt'
[499/4024] ACTION //flutter/shell/plat...a(//build/toolchain/android:clang_arm)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[4015/4024] STAMP obj/flutter/sky/sky.stamp
[4016/4024] ACTION //flutter/testing/s...t(//build/toolchain/android:clang_arm)
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
[4024/4024] STAMP obj/default.stamp

如何切换源码版本

目标引擎版本 857bd6b74c5eb56151bfafe91e7fa6a82b6fee25

 

fatal: Could not parse object '857bd6b74c5eb56151bfafe91e7fa6a82b6fee25'.

 

先 进行 git pull 操作 更新git log找到该版本信息

1
2
git reset --hard 857bd6b74c5eb56151bfafe91e7fa6a82b6fee25
HEAD is now at 857bd6b74c [flutter_releases] Flutter stable 3.3.7 Engine Cherrypicks (#37210)

开始同步

 

gclient sync --with_branch_heads --with_tags --verbose

参考资料


[培训]《安卓高级研修班(网课)》月薪三万计划

最后于 2022-11-24 11:12 被小黄鸭爱学习编辑 ,原因:
收藏
点赞3
打赏
分享
最新回复 (15)
雪    币:
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
wx_莫相惜 2022-5-25 14:57
2
0
十天了大哥 催更
雪    币: 1654
活跃值: (3947)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小黄鸭爱学习 2022-5-31 11:12
3
0
wx_莫相惜 十天了大哥 催更[em_88]
我马上更新
雪    币: 1654
活跃值: (3947)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小黄鸭爱学习 2022-5-31 11:50
4
0
不知道论坛什么帖子可以加精啊
雪    币: 226
活跃值: (1269)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
hpphpp 2022-6-1 21:57
5
0
催更
雪    币: 15
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_uswnoyxt 2022-7-3 04:44
6
0
大佬丢了
雪    币: 1446
活跃值: (1766)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
dreamhake 2022-7-11 09:19
7
0
敢问大佬,有些app用reflutter 重新打包之后闪退怎么解决?
雪    币: 1654
活跃值: (3947)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小黄鸭爱学习 2022-7-11 14:49
8
0
dreamhake 敢问大佬,有些app用reflutter 重新打包之后闪退怎么解决?
有签名校验 这很正常,所以我也不太推荐使用重打包方式进行逆向flutter
雪    币: 1446
活跃值: (1766)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
dreamhake 2022-7-11 17:41
9
0
小黄鸭爱学习 有签名校验 这很正常,所以我也不太推荐使用重打包方式进行逆向flutter
还有其他方式吗?我用 mt 直接去签名校验,貌似没有效果
雪    币: 1654
活跃值: (3947)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小黄鸭爱学习 2022-7-11 17:58
10
0
dreamhake 还有其他方式吗?我用 mt 直接去签名校验,貌似没有效果
mt是什么
雪    币: 227
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
一面 2022-7-15 14:49
11
0
小黄鸭大佬,reflutter 打包闪退有没有啥解决方案,能不能留个联系方式
雪    币: 1654
活跃值: (3947)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
小黄鸭爱学习 2022-7-18 15:25
12
0
一面 小黄鸭大佬,reflutter 打包闪退有没有啥解决方案,能不能留个联系方式
1.检测签名校验
2.是否魔改过引擎源码
雪    币: 1
活跃值: (945)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wx_阿达西 2022-8-10 18:33
13
0
小黄鸭爱学习 有签名校验 这很正常,所以我也不太推荐使用重打包方式进行逆向flutter
请教下大佬,reflutter重打包apk,运行重打包的apk得到dump文件后,在dump文件中找到函数偏移地址,使用frida去hook时,直接使用原始的apk可以吗?一定要reflutter重打包的apk吗。因为我碰到一个问题,重打包的apk可以运行,但是网络不正常(感觉像是断网了,可能是有检测重打包,主动断网的)
雪    币: 1
活跃值: (945)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wx_阿达西 2022-8-10 18:35
14
0
小黄鸭爱学习 有签名校验 这很正常,所以我也不太推荐使用重打包方式进行逆向flutter
dump文件,看起来是去获取函数针对_kDartIsolateSnapshotInstructions的偏移值。我拿到这个偏移值,直接运行原始apk,hook它,获取到_kDartIsolateSnapshotInstructions的地址,加上dump文件中的偏移值,应该就是目标函数的地址了吧
雪    币: 181
活跃值: (62)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wx_*、宁采臣 ゛ 2022-11-2 17:50
15
0
dreamhake 敢问大佬,有些app用reflutter 重新打包之后闪退怎么解决?
我也是签名校验闪退  改了检测点 还是闪退  写的就很离谱  和以前见过的不太一样
雪    币: 237
能力值: ( LV1,RANK:0 )
在线值:
发帖
回帖
粉丝
mb_oniqjhzq 2023-6-17 14:07
16
0
wx_莫相惜 十天了大哥 催更[em_88]
阿萨
游客
登录 | 注册 方可回帖
返回