In-depth study of Flutter and Flutter Engine is necessary. The Engine has been released by The Flutter authorities for developers to modify and learn from, but simply cloning The Flutter Engine repository (github.com) will not build The Engine. It still lacks many necessary third-party libraries. OK, without further ado, let’s do it according to the official tutorial!

precondition

  1. Git config –global http.proxy XXX git config –global http.proxy XXX

  2. Set https_proxy= XXX to temporarily set the proxy

  3. Your Git has SSH configured

1. Configure the Windows development environment

  • Windows SDK

    It is recommended to download Visual Studio 2019 and check the load to automatically install the SDK.

Once installed, find the SDK in Windows Settings apps and features and click Modify.

Change, then click Next, check the first Windows Performance Toolkit option, and finally apply the changes.

  • Setting environment variables
GYP_MSVS_OVERRIDE_PATH="C:\Program Files (x86)/Microsoft Visual Studio/2019/Community" (or your location for Visual Studio) //VS version GYP_MSVS_VERSION = 2019 WINDOWSSDKDIR="C:\Program Files (x86)\Windows Kits\10" (or your location for Windows Kits)Copy the code
  • Enable long address support to open PowerShell, type the following command.
  Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Force
Copy the code

2. Download the deployment tool depot_tools

depot_tools

It is recommended to set environment variables to facilitate the use of the Gclient directive.

3. Pull engine source code

  1. Fork an official repository of Flutter Engine

  2. Create a.gclient file in the folder where you want to put the engine source code. Replace the url with the SSH address you just forked.

solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "[email protected]:<your_name_here>/engine.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
  },
]
Copy the code
  1. Open the terminal and run the command in the directorygclient syncCommand (this command containsgit cloneMake sure yourterminalAs well asgitThe agent has been set up.
  • If you encounter an error in Python’s File, the proxy is not set properly

  • After a successful pull, the directory and terminal should look like this

The pull speed depends on your agent, the file is about 15GB.

4. Build your engine

Assume you have customized the engine or added files and configured the build.gn content

  1. CD to the SRC directory

  2. To prepare the build file, enter python.\flutter\tools\gn –unoptimized

    Gn Help will tell you if you’re curious about parameters

  1. The input terminalninja -C .\out\<dir created by previous step>, the last command will be inoutDirectory generates a new folder, usuallyhost_debug_unopt, replace the contents of Angle brackets with this directory, and then start to compile 6000+ files, which takes a long time.

5. Start your engine

Simple. You just have to have hands.

Flutter run --local-engine-src-path --local-engine=<out generated folder name >Copy the code

The resources

Compiling the engine · flutter/flutter Wiki (github.com)

Setting up the Engine development environment · flutter/flutter Wiki (github.com)