关于编译:
General Compilation Tips
- For local development and testing, it’s generally preferable to use
--unoptbuilds. These builds will have additional logging and checks enabled, and generally use build and link flags that lead to faster compilation and better debugging symbols. If you are trying to do performance testing with a local build, do not use the--unoptflag. - Link Time Optimization: Optimized builds also perform Link Time Optimization of all binaries. This makes the linker take a lot of time and memory to produce binaries. If you need optimized binaries but don’t want to perform LTO, add the
--no-ltoflag. - Android and iOS expect both a
hostandandroid(orios) build. It is critical to recompile the host build after upgrading the Dart SDK (e.g. via agclient syncafter merging up to head), since artifacts from the host build need to be version matched to artifacts in the Android/iOS build. - Web, Desktop, and Fuchsia builds have only one build target (i.e.
hostorfuchsia). - Make sure to exclude the
outdirectory from any backup scripts, as many large binary artifacts are generated. This is also generally true for all of the directories outside of theengine/src/flutterdirectory.
Using a custom Dart SDK
When targeting the host and desktop, on CI we use a pre-built Dart SDK vended by the Dart team. To build and use the SDK from the Dart sources downloaded by gclient sync, after editing those source files, pass the flag --no-prebuilt-dart-sdk to //flutter/tools/gn.
Compiling for Windows
You can only build selected binaries on Windows (mainly gen_snapshot and the desktop embedding).
On Windows, ensure that the engine checkout is not deeply nested. This avoid the issue of the build scripts working with excessively long paths.
- Make sure you have Visual Studio installed (non-Googlers only). Debugging Tools for Windows 10 must be installed.
git pull upstream maininsrc/flutterto update the Flutter Engine repo.- Ensure long path support is enabled on your machine. Launch PowerShell as an administrator and run:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1 -Force
- If you are not a Google employee, you must set the following environment variables to point the depot tools at Visual Studio:
DEPOT_TOOLS_WIN_TOOLCHAIN=0
GYP_MSVS_OVERRIDE_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2019\Community" # (or your location for Visual Studio)
WINDOWSSDKDIR="C:\Program Files (x86)\Windows Kits\10" # (or your location for Windows Kits)
Also, be sure that Python27 is before any other python in your Path.
gclient syncto update your dependencies.- switch to
src/directory. python .\flutter\tools\gn --unoptimizedto prepare your build files.- If you are only building
gen_snapshot:python .\flutter\tools\gn [--unoptimized] --runtime-mode=[debug|profile|release] [--android].
- If you are only building
ninja -C .\out\<dir created by previous step>to build.- If you used a non-debug configuration, use
ninja -C .\out\<dir created by previous step> gen_snapshot. Release and profile are not yet supported for the desktop shell.
- If you used a non-debug configuration, use
python .\flutter\tools\gn --unoptimized --no-prebuilt-dart-sdk
Compiling for the Web
For building the engine for the Web we use the felt tool.
To test Flutter with a local build of the Web engine, add --local-web-sdk=wasm_release to your flutter command, e.g.:
flutter run --local-web-sdk=wasm_release -d chrome
flutter test --local-web-sdk=wasm_release test/path/to/your_test.dart
Compiling for the Web on Windows
Compiling the web engine might take a few extra steps on Windows. Use cmd.exe and “run as administrator”.
- Make sure you have Visual Studio installed. Set the following environment variables. For Visual Studio use the path of the version you installed.
GYP_MSVS_OVERRIDE_PATH = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"GYP_MSVS_VERSION = 2017
- Make sure, depot_tools, ninja and python are installed and added to the path. Also set the following environment variable for depot tools:
DEPOT_TOOLS_WIN_TOOLCHAIN = 0- Tip: if you get a python error try to use Python 2 instead of 3
git pull upstream maininsrc/flutterto update the Flutter Engine repo.gclient syncto update your dependencies.- Tip: If you get a git authentication errors on this step try Git Bash instead
python .\flutter\tools\gn --unoptimized --full-dart-sdkto prepare your build files.ninja -C .\out\<dir created by previous step>to build.
To test Flutter with a local build of the Web engine, add --local-web-sdk=wasm_release to your flutter command, e.g.:
flutter run --local-web-sdk=wasm_release -d chrome
flutter test --local-web-sdk=wasm_release test/path/to/your_test.dart
For testing the engine again use felt tool this time with felt_windows.bat.
felt_windows.bat test
Troubleshooting Compile Errors
Version Solving Failed
From time to time, as the Dart versions increase, you might see dependency errors such as:
The current Dart SDK version is 2.7.0-dev.0.0.flutter-1ef444139c.
Because ui depends on <a pub package> 1.0.0 which requires SDK version >=2.7.0 <3.0.0, version solving failed.
Running gclient sync does not update the tags, there are two solutions:
- under
engine/src/third_party/dartrungit fetch --tags origin - or run gclient sync with with tags parameter:
gclient sync --with_tags
See also: Debugging the engine, which includes instructions on running a Flutter app with a local engine.