一.下载渲染引擎
1.下载引擎时需注意的点
路径不能有中文
工具(后续用到的下载工具)所在的目录需要有可执行权限
2.查看当前Engine版本flutter doctor -v
mac@zhangtao ~ % flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165 darwin-x64, locale
zh-Hans-CN)
• Flutter version 2.5.3 at /Users/mac/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (7 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/mac/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android
Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.1, Build version 13A1030d
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 96.0.4664.55
• No issues found!
- 当前Engine版本是
d3ea636dc5
- Channel stable(稳定版本)
3.查看channel版本flutter channel
mac@zhangtao ~ % flutter channel
Flutter channels:
master
dev
beta
* stable
- 共有4个版本,主分支、开发分支、公共测试版本分支、
稳定版本分支(开发使用的)
- 如果想切换至某个版本
flutter channel xxx
,例如flutter channel dev
4.Github上查看Engine
- Engine
- 我们需要下载到稳定版本
5.查看当前Engine详细的CommitId(d3ea636dc5)
mac@zhangtao internal % cat $FLUTTER_ENGINE
d3ea636dc5d16b56819f3266241e1f708979c233
.zshrc中配置的环境变量(老版本使用.base_profile)
#Flutetr
export FLUTTER=~/flutter
export FLUTTER_ENGINE=${FLUTTER}/bin/internal/engine.version
-
engine
在flutter目录下/bin/internal/engine.version -
cat
常用来显示文件内容 d3ea636dc5d16b56819f3266241e1f708979c233
当前稳定版本的CommitId
6.工具准备(使用到depot_tools)
- Chromium提供的部署工具depot_tools
#depot_tools
export DEPOT_TOOLS=~/depot_tools
//写入环境变量
export PATH=$FLUTTER/bin:DEPOT_TOOLS:$PATH
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
- 默认下载到家目录下也就是
DEPOT_TOOLS
7.安装ant
brew install ant
8.开始下载
- 1.新建目录(路径不能含有中文)
mkdir engine
- 2.创建gclient文件
touch .gclient
- 3.配置gclient文件(保证CommitId一致)
solutions = [
{
"managed": False,
"name": "src/flutter",
"url":
"git@github.com:flutter/engine.git@d3ea636dc5d16b56819f3266241e1f708979c233
2",
"custom_deps": {},
"deps_file": "DEPS",
"safesync_url": "",
}, ]
- 4.执行gclient sync(大概10G的文件)
gclient sync
二.更新渲染引擎
- 更新.gclient文件中的commitId
- 进入src/flutter目录下
git pull
git reset --hard commitID //告诉Git下次下载就下载这个CommitId
- 回到engine目录,也就是.gclient文件所在目录
gclient sync --with_branch_heads --with_tags --verbose
三.编译引擎代码(GN构建、Ninja编译)
1.首先使用GN(是一个生成Ninja)构建文件的元构建系统
- GN -> engine/src/flutter/tools/gn
- 进入
engine/src/flutter/tools
终端目录进行构建 - 构建后的文件会放到
engine/src/out
目录
# 构建iOS设备使用的引擎
# 真机debug版本 -构建后的-> ios_debug_unopt
./gn --ios --unoptimized
# 真机release版本(日常开发使用,如果我们要自定义引擎)-构建后的-> ios_release_unopt
./gn --ios --unoptimized --runtime-mode=release
#模拟器版本 -构建后的-> ios_debug_sim_unopt
./gn --ios --simulator --unoptimized
# 主机端(Mac) -构建后的-> host_debug_unopt
./gn --unoptimized
-
ios_xx_unopt
,Flutter.framework -
host_debug_unopt
,server端,热重载功能
2.使用Ninja编译工程
- 进入
engine/src/out
目录编译 - 使用
ninja -C xxx
进行编译
ninja -C host_debug_unopt && ninja -C ios_debug_sim_unopt && ninja -C
ios_debug_unopt && ninja -C ios_release_unopt
四.安装Ninja(Mac big Sur)
1.首先要先安装re2c
并进入re2c目录
//进入家目录执行
git clone https://github.com/skvadrik/re2c.git && cd re2c
2.执行./autogen.sh
- 如果报错
autoreconf: command not found
,说明未安装automake
- 通过homebrew安装
brew install automake
brew install libtool
- 安装完成后继续执行步骤2
./autogen.sh
3.执行./configure&&make&&make install
- 如果报错
Error: Permission denied @ apply2files - /usr/local/lib/docker/cli-plugins
sudo chown -R $(whoami) $(brew --prefix)/*
- 继续执行
./configure&&make&&make install
4.此时rec2就安装完成了,安装ninja
git clone git://github.com/ninja-build/ninja.git && cd ninja
./configure.py --bootstrap
5.安装cmake
- 安装cmake
brew install cmake
- 执行以下命令
cmake -Bbuild-cmake -H.
cmake --build build-cmake
6.配置Ninja
- 1.将
ninja
可执行文件拷贝到user/bin目录下
cp ninja /usr/bin/
- 报错
cp: /usr/bin/ninja: Operation not permitted
,可以在恢复模式
下关闭了Rootless
解决 - 可能会报错
cp: /usr/bin/ninja: Read-only file system
,bin文件只有只读权限,目前没找到解决办法
-
综上,
因此我这里只能采用的配置环境变量方式
- 2.配置
Ninja
环境变量
#Flutetr
export FLUTTER=~/flutterSDK
export NINJA=~/re2c/ninja
export PATH=$FLUTTER/bin:$PATH
FLUTTER_ENGINE="${FLUTTER}/bin/internal/engine.version"
export PATH="/Users/mac/re2c/ninja":"$PATH"
- 3.测试Ninja是否安装成功
ninja --version
- 当出现下列数据时,ninja安装成功
mac@user ninja % ninja --version
1.10.2.git
-
至此,就可以使用ninja去构建版本了
- 我这里有一个构建好的版本Flutter_engine_d3ea636dc5(
提取码11rq
;编译了4个版本,文件有点大)