翻墙

  1. 保证terminal走代理流量
  2. 使用git config --global http.proxy "localhost:port",设置代理。

​ port是端口号,根据不同的vpn不一样,我这里使用的是lartern,端口是50321。

  1. 操作执行 git config --global http.proxy "localhost:50321"

    具体的端口号根据翻墙软件的相关配置来

    git config --global https.proxy http://127.0.0.1:1080
    git config --global https.proxy https://127.0.0.1:1080
    git config --global http.proxy 'socks5://127.0.0.1:1080' 
    git config --global https.proxy 'socks5://127.0.0.1:1080'
    //取消
    git config --global --unset http.proxy
    git config --global --unset https.proxy

配置depot_tools工具

depot_tools是个工具包,里面包含gclient、gn和ninja等工具。是Google为解决Chromium源码管理问题为Chromium提供的源代码管理的一个工具。Flutter源码同步也需要依赖depot_tools工具。

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

//将depot_tools加入环境变量
export PATH="$PATH:/path/to/depot_tools"

//使用可以参考
https://dev.chromium.org/developers/how-tos/depottools
https://commondatastorage.googleapis.com/chrome-infra-docs/flat/depot_tools/docs/html/depot_tools_tutorial.htm

下载源码

  1. 从官网fork工程到自己工程,https://github.com/flutter/engine
  2. 配置ssh秘钥 https://help.github.com/artic...
  3. 在engine目录下创建.gclient文件用于同步源码

    solutions = [
      {
        "managed": False,
        "name": "src/flutter",
        "url": "git@github.com:chiqtv/engine.git",
        "custom_deps": {},
        "deps_file": "DEPS",
        "safesync_url": "",
      },
    ]
  4. 同步代码

    cd /path/to/engine
    gclient sync //获取flutter依赖的源码,它会自动运行git clone和其他命令

编译

  1. 编译选项,通过./flutter/tools/gn --help命令查看

    usage: gn [-h] [--unoptimized]
              [--runtime-mode {debug,profile,release,jit_release}] [--interpreter]
              [--dart-debug] [--full-dart-debug]
              [--target-os {android,ios,linux,fuchsia}] [--android]
              [--android-cpu {arm,x64,x86,arm64}] [--ios] [--ios-cpu {arm,arm64}]
              [--simulator] [--fuchsia] [--linux-cpu {x64,x86,arm64,arm}]
              [--fuchsia-cpu {x64,arm64}] [--arm-float-abi {hard,soft,softfp}]
              [--goma] [--no-goma] [--lto] [--no-lto] [--clang] [--no-clang]
              [--clang-static-analyzer] [--no-clang-static-analyzer]
              [--target-sysroot TARGET_SYSROOT]
              [--target-toolchain TARGET_TOOLCHAIN]
              [--target-triple TARGET_TRIPLE]
              [--operator-new-alignment OPERATOR_NEW_ALIGNMENT] [--enable-vulkan]
              [--enable-fontconfig] [--enable-skshaper]
              [--enable-vulkan-validation-layers] [--embedder-for-target]
              [--coverage] [--out-dir OUT_DIR] [--full-dart-sdk]
              [--no-full-dart-sdk] [--ide IDE] [--disable-desktop-embeddings]
              [--build-glfw-shell] [--no-build-glfw-shell] [--bitcode]
              [--stripped] [--no-stripped] [--asan] [--lsan] [--msan] [--tsan]
  2. Android arm64的release优化版

    cd /path/to/engine/src/
      ./flutter/tools/gn --android-cpu arm64 --no-lto --runtime-mode=release
    ninja -C out/host_release_arm64 -j 8   //生成Host编译产物存放文件
      
    ./flutter/tools/gn --android --android-cpu arm64 --no-lto --runtime-mode=release 
    ninja -C out/android_release_arm64 -j 8 //生成Android编译产物存放文件
      
      
     //编译的时候有一个错误,需要把lto优化给关闭了
      https://github.com/flutter/flutter/issues/57207
    
  3. Android armeabi支持

    不支持Android armeabi,最低支持armeabi-v7a,从个人的感觉来说,小厂的应用开发应该很快就过可以过度到支持arm64了,不支持arm64的主流旗舰机主要是海思935,高通801,海思聪950,高通聪808之后都是支持arm64的cpu。

  4. 使用编译出来的flutter

    //local-engine-src-path:指定Flutter引擎存储库的路径,也就是src根目录的绝对路径
    //local-engine:指定使用哪个引擎版本

flutter build apk --target-platform android-arm64 --local- engine=android_release_arm64 --local-engine-src- path=/Users/xiaoyao/Documents/code/flutter/engine/src


戮世帝尊
0 声望0 粉丝

风满楼,卷黄沙,舞剑春秋,名震天下。