{"id":250,"date":"2023-10-11T23:53:20","date_gmt":"2023-10-11T15:53:20","guid":{"rendered":"http:\/\/www.sourcecool.com\/?p=250"},"modified":"2023-10-11T23:53:20","modified_gmt":"2023-10-11T15:53:20","slug":"flutteranzhuanghebianyiyijidiaoshidazahui","status":"publish","type":"post","link":"http:\/\/www.sourcecool.com\/index.php\/2023\/10\/11\/flutteranzhuanghebianyiyijidiaoshidazahui\/","title":{"rendered":"flutter\u5b89\u88c5\u548c\u7f16\u8bd1\u4ee5\u53ca\u8c03\u8bd5\u5927\u6742\u70e9"},"content":{"rendered":"\n<p>\u5173\u4e8e\u7f16\u8bd1\uff1a<\/p>\n\n\n\n<h2 id=\"user-content-general-compilation-tips\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#general-compilation-tips\">General Compilation Tips<\/a><\/h2>\n\n\n\n<ul>\n<li>For local development and testing, it&#8217;s generally preferable to use&nbsp;<code>--unopt<\/code>&nbsp;builds. 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&nbsp;<code>--unopt<\/code>&nbsp;flag.<\/li>\n\n\n\n<li>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&#8217;t want to perform LTO, add the&nbsp;<code>--no-lto<\/code>&nbsp;flag.<\/li>\n\n\n\n<li>Android and iOS expect both a&nbsp;<code>host<\/code>&nbsp;and&nbsp;<code>android<\/code>&nbsp;(or&nbsp;<code>ios<\/code>) build. It is critical to recompile the host build after upgrading the Dart SDK (e.g. via a&nbsp;<code>gclient sync<\/code>&nbsp;after merging up to head), since artifacts from the host build need to be version matched to artifacts in the Android\/iOS build.<\/li>\n\n\n\n<li>Web, Desktop, and Fuchsia builds have only one build target (i.e.&nbsp;<code>host<\/code>&nbsp;or&nbsp;<code>fuchsia<\/code>).<\/li>\n\n\n\n<li>Make sure to exclude the&nbsp;<code>out<\/code>&nbsp;directory from any backup scripts, as many large binary artifacts are generated. This is also generally true for all of the directories outside of the&nbsp;<code>engine\/src\/flutter<\/code>&nbsp;directory.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"user-content-using-a-custom-dart-sdk\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#using-a-custom-dart-sdk\">Using a custom Dart SDK<\/a><\/h2>\n\n\n\n<p>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\u00a0<code>gclient sync<\/code>, after editing those source files, pass the flag\u00a0<code>--no-prebuilt-dart-sdk<\/code>\u00a0to\u00a0<code>\/\/flutter\/tools\/gn<\/code>.<\/p>\n\n\n\n<h2 id=\"user-content-compiling-for-windows\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#compiling-for-windows\">Compiling for Windows<\/a><\/h2>\n\n\n\n<p>You can only build selected binaries on Windows (mainly&nbsp;<code>gen_snapshot<\/code>&nbsp;and the desktop embedding).<\/p>\n\n\n\n<p>On Windows, ensure that the engine checkout is not deeply nested. This avoid the issue of the build scripts working with excessively long paths.<\/p>\n\n\n\n<ol>\n<li>Make sure you have Visual Studio installed (non-Googlers only).&nbsp;<a href=\"https:\/\/docs.microsoft.com\/en-us\/windows-hardware\/drivers\/debugger\/debugger-download-tools#small-classic-windbg-preview-logo-debugging-tools-for-windows-10-windbg\">Debugging Tools for Windows 10<\/a>&nbsp;must be installed.<\/li>\n\n\n\n<li><code>git pull upstream main<\/code>&nbsp;in&nbsp;<code>src\/flutter<\/code>&nbsp;to update the Flutter Engine repo.<\/li>\n\n\n\n<li>Ensure long path support is enabled on your machine. Launch PowerShell as an administrator and run:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>Set-ItemProperty -Path \"HKLM:\\SYSTEM\\CurrentControlSet\\Control\\FileSystem\" -Name \"LongPathsEnabled\" -Value 1 -Force\n<\/code><\/pre>\n\n\n\n<ol start=\"4\">\n<li>If you are not a Google employee, you must set the following environment variables to point the depot tools at Visual Studio:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>DEPOT_TOOLS_WIN_TOOLCHAIN=0\nGYP_MSVS_OVERRIDE_PATH=\"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\" # (or your location for Visual Studio)\nWINDOWSSDKDIR=\"C:\\Program Files (x86)\\Windows Kits\\10\" # (or your location for Windows Kits)<\/code><\/pre>\n\n\n\n<p>Also, be sure that Python27 is before any other python in your Path.<\/p>\n\n\n\n<ol start=\"5\">\n<li><code>gclient sync<\/code>&nbsp;to update your dependencies.<\/li>\n\n\n\n<li>switch to&nbsp;<code>src\/<\/code>&nbsp;directory.<\/li>\n\n\n\n<li><code>python .\\flutter\\tools\\gn --unoptimized<\/code>\u00a0to prepare your build files.\n<ul>\n<li>If you are only building&nbsp;<code>gen_snapshot<\/code>:&nbsp;<code>python .\\flutter\\tools\\gn [--unoptimized] --runtime-mode=[debug|profile|release] [--android]<\/code>.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>ninja -C .\\out\\&lt;dir created by previous step&gt;<\/code>\u00a0to build.\n<ul>\n<li>If you used a non-debug configuration, use&nbsp;<code>ninja -C .\\out\\&lt;dir created by previous step&gt; gen_snapshot<\/code>. Release and profile are not yet supported for the desktop shell.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code><code>python .\\flutter\\tools\\gn --unoptimized<span style=\"background-color: initial; color: initial; font-family: inherit; font-size: inherit;\"> --no-prebuilt-dart-sdk<\/span><\/code>\n<\/code><\/pre>\n\n\n\n<h2 id=\"user-content-compiling-for-the-web\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#compiling-for-the-web\">Compiling for the Web<\/a><\/h2>\n\n\n\n<p>For building the engine for the Web we use the&nbsp;<a href=\"https:\/\/github.com\/flutter\/engine\/blob\/main\/lib\/web_ui\/README.md\">felt<\/a>&nbsp;tool.<\/p>\n\n\n\n<p>To test Flutter with a local build of the Web engine, add&nbsp;<code>--local-web-sdk=wasm_release<\/code>&nbsp;to your&nbsp;<code>flutter<\/code>&nbsp;command, e.g.:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>flutter run --local-web-sdk=wasm_release -d chrome\nflutter test --local-web-sdk=wasm_release test\/path\/to\/your_test.dart\n<\/code><\/pre>\n\n\n\n<h2 id=\"user-content-compiling-for-the-web-on-windows\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#compiling-for-the-web-on-windows\">Compiling for the Web on Windows<\/a><\/h2>\n\n\n\n<p>Compiling the web engine might take a few extra steps on Windows. Use cmd.exe and &#8220;run as administrator&#8221;.<\/p>\n\n\n\n<ol>\n<li>Make sure you have Visual Studio installed. Set the following environment variables. For Visual Studio use the path of the version you installed.\n<ul>\n<li><code>GYP_MSVS_OVERRIDE_PATH = \"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\"<\/code><\/li>\n\n\n\n<li><code>GYP_MSVS_VERSION = 2017<\/code><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Make sure, depot_tools, ninja and python are installed and added to the path. Also set the following environment variable for depot tools:\n<ul>\n<li><code>DEPOT_TOOLS_WIN_TOOLCHAIN = 0<\/code><\/li>\n\n\n\n<li>Tip: if you get a python error try to use Python 2 instead of 3<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>git pull upstream main<\/code>&nbsp;in&nbsp;<code>src\/flutter<\/code>&nbsp;to update the Flutter Engine repo.<\/li>\n\n\n\n<li><code>gclient sync<\/code>\u00a0to update your dependencies.\n<ul>\n<li>Tip: If you get a git authentication errors on this step try Git Bash instead<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><code>python .\\flutter\\tools\\gn --unoptimized --full-dart-sdk<\/code>&nbsp;to prepare your build files.<\/li>\n\n\n\n<li><code>ninja -C .\\out\\&lt;dir created by previous step&gt;<\/code>&nbsp;to build.<\/li>\n<\/ol>\n\n\n\n<p>To test Flutter with a local build of the Web engine, add&nbsp;<code>--local-web-sdk=wasm_release<\/code>&nbsp;to your&nbsp;<code>flutter<\/code>&nbsp;command, e.g.:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>flutter run --local-web-sdk=wasm_release -d chrome\nflutter test --local-web-sdk=wasm_release test\/path\/to\/your_test.dart\n<\/code><\/pre>\n\n\n\n<p>For testing the engine again use&nbsp;<a href=\"https:\/\/github.com\/flutter\/engine\/blob\/main\/lib\/web_ui\/README.md\">felt<\/a>&nbsp;tool this time with felt_windows.bat.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>felt_windows.bat test<\/code><\/pre>\n\n\n\n<h2 id=\"user-content-troubleshooting-compile-errors\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#troubleshooting-compile-errors\">Troubleshooting Compile Errors<\/a><\/h2>\n\n\n\n<h3 id=\"user-content-version-solving-failed\"><a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Compiling-the-engine#version-solving-failed\">Version Solving Failed<\/a><\/h3>\n\n\n\n<p>From time to time, as the Dart versions increase, you might see dependency errors such as:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The current Dart SDK version is 2.7.0-dev.0.0.flutter-1ef444139c.\n\nBecause ui depends on &lt;a pub package&gt; 1.0.0 which requires SDK version &gt;=2.7.0 &lt;3.0.0, version solving failed.\n<\/code><\/pre>\n\n\n\n<p>Running&nbsp;<code>gclient sync<\/code>&nbsp;does not update the tags, there are two solutions:<\/p>\n\n\n\n<ol>\n<li>under&nbsp;<code>engine\/src\/third_party\/dart<\/code>&nbsp;run&nbsp;<code>git fetch --tags origin<\/code><\/li>\n\n\n\n<li>or run gclient sync with with tags parameter:&nbsp;<code>gclient sync --with_tags<\/code><\/li>\n<\/ol>\n\n\n\n<p><em>See also:&nbsp;<a href=\"https:\/\/github.com\/flutter\/flutter\/wiki\/Debugging-the-engine\">Debugging the engine<\/a>, which includes instructions on running a Flutter app with a local engine.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e\u7f16\u8bd1\uff1a General C&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":[],"categories":[14],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/250"}],"collection":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/comments?post=250"}],"version-history":[{"count":2,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/250\/revisions"}],"predecessor-version":[{"id":252,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/posts\/250\/revisions\/252"}],"wp:attachment":[{"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/media?parent=250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/categories?post=250"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sourcecool.com\/index.php\/wp-json\/wp\/v2\/tags?post=250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}