flutter-setting-up-on-windows
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSetting Up Flutter for Windows Development
为Windows开发搭建Flutter环境
Contents
目录
Core Requirements
核心要求
Configure the Windows environment to support both Flutter framework execution and native C/C++ compilation. Differentiate strictly between Visual Studio (required for Windows desktop C++ compilation) and VS Code (the recommended Dart/Flutter code editor).
配置Windows环境以支持Flutter框架运行和原生C/C++编译。严格区分Visual Studio(Windows桌面C++编译必需)和VS Code(推荐的Dart/Flutter代码编辑器)。
Workflow: Installing and Configuring the SDK
流程:安装和配置SDK
Follow this sequential workflow to initialize the Flutter SDK on a Windows machine.
- Download the latest stable Flutter SDK for Windows.
- Extract the SDK to a directory with standard user privileges (e.g., ). Do not install in protected directories like
C:\src\flutter.C:\Program Files\ - Copy the absolute path to the Flutter SDK's directory.
bin - Open Windows Environment Variables settings and append the directory path to the system or user
binvariable.PATH - Open a new terminal session to apply the changes.
PATH - Feedback Loop: Run validator -> review errors -> fix.
- Execute .
flutter doctor -v - Review the output for missing dependencies or path issues.
- Resolve any flagged errors before proceeding to tooling setup.
- Execute
按照以下顺序流程在Windows机器上初始化Flutter SDK。
- 下载适用于Windows的最新稳定版Flutter SDK。
- 将SDK解压到具有标准用户权限的目录(例如)。不要安装在受保护目录如
C:\src\flutter中。C:\Program Files\ - 复制Flutter SDK的目录的绝对路径。
bin - 打开Windows环境变量设置,将目录路径添加到系统或用户
bin变量中。PATH - 打开新的终端会话以应用更改。
PATH - 反馈循环: 运行验证工具 -> 查看错误 -> 修复问题。
- 执行。
flutter doctor -v - 查看输出中的缺失依赖项或路径问题。
- 在进行工具配置前解决所有标记的错误。
- 执行
Workflow: Configuring Tooling and IDEs
流程:配置工具与IDE
- Install Visual Studio (not VS Code).
- Select and install the Desktop development with C++ workload during the Visual Studio installation process. This is mandatory for compiling Windows desktop applications.
- Install your preferred code editor (VS Code, Android Studio, or IntelliJ).
- Install the official Flutter and Dart extensions/plugins within your chosen editor.
- 安装Visual Studio(不是VS Code)。
- 在Visual Studio安装过程中选择并安装使用C++的桌面开发工作负载。这是编译Windows桌面应用的必需项。
- 安装你偏好的代码编辑器(VS Code、Android Studio或IntelliJ)。
- 在所选编辑器中安装官方的Flutter和Dart扩展/插件。
Workflow: Configuring Target Platforms
流程:配置目标平台
Apply conditional logic based on the specific platform you are targeting for development.
If targeting Windows Desktop:
- Ensure the Visual Studio C++ workload is fully updated.
- Restart your IDE so it detects the Windows desktop device.
- To disable platforms you do not intend to compile for, execute (e.g.,
flutter config --no-enable-<platform>).flutter config --no-enable-windows-desktop
If targeting Android on Windows:
- For physical devices: Enable Developer Options and USB debugging on the device. Install the specific OEM USB drivers for Windows.
- For emulators: Open the Android Virtual Device (AVD) manager. Under "Emulated Performance" -> "Graphics acceleration", select an option specifying "Hardware" to enable hardware acceleration.
- Verify the device connection by running .
flutter devices
根据你要开发的特定平台应用条件逻辑。
如果目标是Windows桌面:
- 确保Visual Studio C++工作负载已完全更新。
- 重启IDE以使其检测到Windows桌面设备。
- 要禁用你不打算编译的平台,执行(例如
flutter config --no-enable-<platform>)。flutter config --no-enable-windows-desktop
如果目标是Windows上的Android:
- 对于物理设备: 在设备上启用开发者选项和USB调试。为Windows安装特定的OEM USB驱动。
- 对于模拟器: 打开Android虚拟设备(AVD)管理器。在"模拟性能"->"图形加速"下,选择指定"硬件"的选项以启用硬件加速。
- 通过运行验证设备连接。
flutter devices
Workflow: Building and Packaging for Windows
流程:为Windows构建和打包
To distribute a Windows desktop application, assemble the compiled executable and its required dependencies into a single distributable archive.
- Execute to compile the release build.
flutter build windows - Navigate to .
build\windows\runner\Release\ - Create a new staging directory for the distribution zip.
- Copy the following assets from the directory into the staging directory:
Release- The application executable ().
.exe - All generated files.
.dll - The entire directory.
data
- The application executable (
- Copy the required Visual C++ redistributables into the staging directory alongside the executable:
msvcp140.dllvcruntime140.dllvcruntime140_1.dll
- Compress the staging directory into a file for distribution.
.zip
要分发Windows桌面应用,需将编译后的可执行文件及其所需依赖项组装成单个可分发压缩包。
- 执行以编译发布版本。
flutter build windows - 导航到目录。
build\windows\runner\Release\ - 为分发压缩包创建一个新的临时目录。
- 将目录中的以下资源复制到临时目录:
Release- 应用可执行文件()。
.exe - 所有生成的文件。
.dll - 整个目录。
data
- 应用可执行文件(
- 将所需的Visual C++可再发行组件复制到临时目录中与可执行文件同级的位置:
msvcp140.dllvcruntime140.dllvcruntime140_1.dll
- 将临时目录压缩为文件以便分发。
.zip
Workflow: Generating and Installing Certificates
流程:生成和安装证书
If you require a self-signed certificate for MSIX packaging or local testing, use OpenSSL.
- Install OpenSSL and add its directory to your
binenvironment variable.PATH - Generate a private key:
openssl genrsa -out mykeyname.key 2048 - Generate a Certificate Signing Request (CSR):
openssl req -new -key mykeyname.key -out mycsrname.csr - Generate the signed certificate (CRT):
openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000 - Generate the file:
.pfxopenssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt - Install the certificate on the local Windows machine. Place it in the Certificate Store under Trusted Root Certification Authorities prior to installing the application.
.pfx
如果需要用于MSIX打包或本地测试的自签名证书,请使用OpenSSL。
- 安装OpenSSL并将其目录添加到你的
bin环境变量中。PATH - 生成私钥:
openssl genrsa -out mykeyname.key 2048 - 生成证书签名请求(CSR):
openssl req -new -key mykeyname.key -out mycsrname.csr - 生成已签名证书(CRT):
openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000 - 生成文件:
.pfxopenssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt - 在本地Windows机器上安装证书。在安装应用前,将其放置在受信任的根证书颁发机构下的证书存储中。
.pfx
Examples
示例
Windows Distribution Directory Structure
Windows分发目录结构
When assembling your Windows build for distribution, ensure the directory structure strictly matches the following layout before zipping:
text
Release_Archive/
│ my_flutter_app.exe
│ flutter_windows.dll
│ msvcp140.dll
│ vcruntime140.dll
│ vcruntime140_1.dll
│
└───data/
│ app.so
│ icudtl.dat
│ ...在组装Windows构建版本以进行分发时,确保在压缩前目录结构严格匹配以下布局:
text
Release_Archive/
│ my_flutter_app.exe
│ flutter_windows.dll
│ msvcp140.dll
│ vcruntime140.dll
│ vcruntime140_1.dll
│
└───data/
│ app.so
│ icudtl.dat
│ ...