Repository navigation
Compiling the engine
These steps build the engine used by flutter run for Android devices.
Run the following steps, from the src directory created in Setting up the Engine development environment:
-
git pull upstream masterinsrc/flutterto update the Flutter Engine repo. -
gclient syncto update dependencies. -
Prepare your build files
-
./flutter/tools/gn --android --unoptimizedfor device-side executables. -
./flutter/tools/gn --android --android-cpu x86 --unoptimizedfor x86 emulators. -
./flutter/tools/gn --android --android-cpu x64 --unoptimizedfor x64 emulators. -
./flutter/tools/gn --unoptimizedfor host-side executables, needed to compile the code.
-
-
Build your executables
-
ninja -C out/android_debug_unoptfor device-side executables. -
ninja -C out/android_debug_unopt_x86for x86 emulators. -
ninja -C out/android_debug_unopt_x64for x64 emulators. -
ninja -C out/host_debug_unoptfor host-side executables. - These commands can be combined. Ex:
ninja -C out/android_debug_unopt && ninja -C out/host_debug_unopt - For Googlers, consider also using the option
-j 100to parallelize the build using Goma.
-
This builds a debug-enabled ("unoptimized") binary configured to run Dart in checked mode ("debug"). There are other versions, see Flutter's modes.
If you're going to be debugging crashes in the engine, make sure you add
android:debuggable="true" to the <application> element in the
android/AndroidManifest.xml file for the Flutter app you are using
to test the engine.
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the android_debug_unopt build to debug the engine on a device, and
android_debug_unopt_x64 to debug in on a simulator.
The following script will update all the builds that matter if you're developing on Linux and testing on Android and created the .gclient file in ~/dev/engine:
set -ex
cd ~/dev/engine/src/flutter
git fetch upstream
git rebase upstream/master
gclient sync
cd ..
flutter/tools/gn --unoptimized --runtime-mode=debug
flutter/tools/gn --android --unoptimized --runtime-mode=debug
flutter/tools/gn --android --unoptimized --runtime-mode=profile
flutter/tools/gn --android --unoptimized --runtime-mode=release
flutter/tools/gn --android --runtime-mode=debug
flutter/tools/gn --android --runtime-mode=profile
flutter/tools/gn --android --runtime-mode=release
cd out
find . -mindepth 1 -maxdepth 1 -type d | xargs -n 1 sh -c 'ninja -C $0 || exit 255'These steps build the engine used by flutter run for iOS devices.
Run the following steps, from the src directory created in the steps above:
-
git pull upstream masterinsrc/flutterto update the Flutter Engine repo. -
gclient syncto update dependencies. -
./flutter/tools/gn --ios --unoptimizedto prepare build files for device-side executables (or--ios --simulator --unoptimizedfor simulator).
- This also produces an Xcode project for working with the engine source code at
out/ios_debug_unopt - For a discussion on the various flags and modes, see Flutter's modes.
-
./flutter/tools/gn --unoptimizedto prepare the build files for host-side executables. -
ninja -C out/ios_debug_unopt && ninja -C out/host_debug_unoptto build all artifacts (useout/ios_debug_sim_unoptfor Simulator).- For Googlers, consider also using the option
-j 100to parallelize the build using Goma.
- For Googlers, consider also using the option
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the ios_debug_unopt build to debug the engine on a device, and
ios_debug_sim_unopt to debug in on a simulator.
If you are debugging crashes in the engine, you can connect the LLDB debugger from Xcode by opening ios/Runner.xcworkspace and starting the application by clicking the Run button (CMD + R).
To debug non-crashing code, open Xcode with ios/Runner.xcworkspace, expand Flutter->Runner->Supporting Files->main.m in the Runner project. Put a breakpoint in main() then set your desired breakpoint in the engine in lldb via breakpoint set -....
Using Xcode in this way will set a $LOCAL_ENGINE variable in your Generated.xcconfig file for the Flutter application. This variable will be set until you run flutter run again with either a different --local-engine option, or with none at all (which will unset it). This is important to note if you plan to re-run your Flutter Runner.xcodeproj directly from Xcode.
These steps build the engine used by flutter test on a host workstation.
-
git pull upstream masterinsrc/flutterto update the Flutter Engine repo. -
gclient syncto update your dependencies. -
./flutter/tools/gn --unoptimizedto prepare your build files.-
--unoptimizeddisables C++ compiler optimizations and does not strip debug symbols.
-
-
ninja -C out/host_debug_unoptto build a desktop unoptimized binary.- If you skipped
--upoptimized, useninja -C out/host_debuginstead. - For Googlers, consider also using the option
-j 1000to parallelize the build using Goma.
- If you skipped
See The flutter tool for instructions on how to use the flutter tool with a local engine.
You will typically use the host_debug_unopt build in this setup.
You can only build selected binaries on Windows (mainly gen_snapshot).
-
Make sure you have Visual Studio installed (non-Googlers only).
-
git pull upstream masterinsrc/flutterto update the Flutter Engine repo. -
gclient syncto update your dependencies. -
python .\flutter\tools\gn [--unoptimized] --runtime-mode=[debug|profile|release] [--android]to prepare your build files. -
ninja -C .\out\<dir created by previous step> gen_snapshotto build.
官方文档和代码一日一变,这里做几个阶段性稳定版本的记录和备份 简书博客