回复
Flutter Engine 下载及编译 原创 精华
jerckNing
发布于 2021-10-14 17:31
浏览
1收藏
一、Windows环境下Flutter引擎源码下载
1、下载depot_tools及配置环境变量
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
下载完成后配置环境变量
path中添加
注意环境变量要放到python环境变量之前
C:\depot_tools\depot_tools
新增一个系统变量
名为“DEPOT_TOOLS_WIN_TOOLCHAIN“,值为”0“。该变量的作用是告诉depot_tools使用本地安装的 Visual Studio版本(depot_tools默认是使用google内部版本)。
在cmd中运行gclient命令,此时无任何提示,会下载部分资源,可以观察depot_tools文件夹
D:\MyData\ningzhen>gclient`
WARNING: Your metrics.cfg file was invalid or nonexistent. A new one will be created.
Usage: gclient.py <command> [options]
Meta checkout dependency manager for Git.
Commands are:
config creates a .gclient file in the current directory
diff displays local diff for every dependencies
fetch fetches upstream commits for all modules
flatten flattens the solutions into a single DEPS file
getdep gets revision information and variable values from a DEPS file
grep greps through git repos managed by gclient
help prints list of commands or help for a specific command
metrics reports, and optionally modifies, the status of metric collection`
pack generates a patch which can be applied at the root of the tree`
recurse operates [command args ...] on all the dependencies`
revert reverts all modifications in every dependencies`
revinfo outputs revision info mapping for the client and its dependencies`
root outputs the solution root (or current dir if there isn't one)`
runhooks runs hooks for files that have been modified in the local working copy`
setdep modifies dependency revisions and variable values in a DEPS file`
status shows modification status for every dependencies`
sync checkout/update all modules`
validate validates the .gclient and DEPS syntax`
verify verifies the DEPS file deps are only from allowed_hosts`
Options:
--version show program's version number and exit`
-h, --help show this help message and exit`
-j JOBS, --jobs=JOBS Specify how many SCM commands can run in parallel;`
`defaults to 8 on this machine`
-v, --verbose Produces additional output for diagnostics. Can be`
`used up to three times for more logging info.`
--gclientfile=CONFIG_FILENAME`
`Specify an alternate .gclient file`
--spec=SPEC create a gclient file containing the provided string.`
`Due to Cygwin/Python brokenness, it can't contain any`
`newlines.`
--no-nag-max Ignored for backwards compatibility.
2、下载Flutter Engine源码
第一次下载可以使用fetch flutter命令,
后面更新使用gclient sync命令
会在目录下创建.gclient文件
solutions = [
{
"custom_deps": {},
"deps_file": "DEPS",
"managed": False,
"name": "src/flutter",
"safesync_url": "",
"url": "https://github.com/flutter/engine.git",
},
]
开始下载
C:\Flutter_Engine>gclient sync
1>________ running 'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://github.com/flutter/engine.git C:\Flutter_Engine\src\_gclient_flutter_8wjc56ou' in 'C:\Flutter_Engine'`
1>Cloning into 'C:\Flutter_Engine\src\_gclient_flutter_8wjc56ou'...`
1>remote: Enumerating objects: 252166, done.`
1>remote: Counting objects: 100% (113/113), done.`
1>remote: Compressing objects: 100% (71/71), done.`
1>Receiving objects: 12% (31628/252166), 51.84 MiB | 383.00 KiB/s
二、MAC/Linux 下载编译FlutterEngine
1、下载depot_tools及配置环境变量
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git
配置环境变量
export PATH="$PATH:/path/to/depot_tools"
2、设置代理
- 在~/.bash_profile 文件中,添加如下代码:
function proxy_off(){
unset http_proxy
unset https_proxy
unset ftp_proxy
unset rsync_proxy
echo -e "已关闭代理"
}
#注意,根据自己的配置设置有可能会是1080或1086
function proxy_on() {
export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
export http_proxy="http://127.0.0.1:1087"
export https_proxy=$http_proxy
export ftp_proxy=$http_proxy
export rsync_proxy=$http_proxy
export HTTP_PROXY=$http_proxy
export HTTPS_PROXY=$http_proxy
export FTP_PROXY=$http_proxy
export RSYNC_PROXY=$http_proxy
echo -e "已开启代理"
}
-
执行source ~/.bash_profile,使其立刻生效。
-
需要使用代理时开启ss全局模式,然后打开终端,输入proxy_on就会启动。如果需要关闭,只需要输入proxy_off。
-
判断终端是否走了代理服务器
curl cip.cc
-
该设置仅对当前终端窗口生效,关闭窗口,下次需要在设置一次proxy_on
3、第一次执行gclient下载对应的资源
gclient
执行此命令,没有任何提示,可以关注depot_tools文件夹大小
4、fetch flutter开始下载
mkdir FlutterEngine
fetch flutter //会创建.gclient文件后会开始同步
5、下载完成后,开始编译
我们使用到的构建参数主要有以下几种
--android 指定android平台
--ios 指定ios平台
--runtime-mode debug,profile,release,jit_release 前三个大家应该都熟,第四个jit_release猜测应该是支持hot_reload的release ([Flutter's modes](https://github.com/flutter/flutter/wiki/Flutter%27s-modes)官网里没看到说明呀 )
--unoptimized 默认是optimized优化过的
--android-cpu {arm,x64,x86,arm64} 默认是arm(对应arm-v7)
--ios --ios-cpu {arm,arm64}
构建Android产物
Android的arm的debug优化版
cd src/
./flutter/tools/gn --android
ninja -C out/android_debug -j 8
./flutter/tools/gn
ninja -C out/host_debug -j 8
Android arm64的release优化版
cd src/
./flutter/tools/gn --android --android-cpu arm64 --runtime-mode=release
ninja -C out/android_release_arm64 -j 8
./flutter/tools/gn --android-cpu arm64 --runtime-mode=release
ninja -C out/host_release_arm64 -j 8
Android x64的profile非优化版
cd src/
./flutter/tools/gn --android --android-cpu x64 --unoptimized --runtime-mode=profile
ninja -C out/android_profile_unopt_x64 -j 8
./flutter/tools/gn --android-cpu x64 --unoptimized --runtime-mode=profile
ninja -C out/host_profile_unopt_x64 -j 8
Android使用本地引擎
终端命令行参数传入
gradlew clean assembleDebug -PlocalEngineOut=engine/src/out/android_debug_unopt
或者
在gradle.properties文件中加入如下内容
localEngineOut=engine/src/out/android_debug_unopt
或者直接使用flutter的build方式
flutter build apk --local-engine=android_debug_unopt --local-engine-src-path=/engine/src
6、Flutter Engine 离线包下载
链接:https://pan.baidu.com/s/1ytKrnxW9QqKF9oxIjFj5DA
提取码:4wsm
©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
赞
3
收藏 1
回复
相关推荐