flutter-environment-setup-windows by flutter/skills
npx skills add https://github.com/flutter/skills --skill flutter-environment-setup-windows配置 Windows 开发环境,用于构建面向 Windows 桌面和 Android 的 Flutter 应用程序。分析系统要求,修改环境变量,安装必要的 C++ 工具链,管理特定平台的配置,并为本地 Windows 应用程序部署生成自签名证书。假设主机运行 Windows 10 或 11,并且拥有进行系统修改所需的管理员权限。
配置 Flutter SDK 和环境变量 将 Flutter SDK 解压到一个安全的、用户可写的目录(例如 C:\develop\flutter)。不要将其放在 C:\Program Files\ 中。执行以下 PowerShell 命令,将 Flutter 的 bin 目录添加到用户的 PATH 环境变量中:
$flutterBinPath = "C:\develop\flutter\bin" $currentUserPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) if ($currentUserPath -notmatch [regex]::Escape($flutterBinPath)) { [Environment]::SetEnvironmentVariable("Path", "$currentUserPath;$flutterBinPath", [EnvironmentVariableTarget]::User) }
安装 Windows 工具 要编译 Windows 桌面应用程序,严格需要 Visual Studio(不是 VS Code)。安装 Visual Studio 并选择“使用 C++ 的桌面开发”工作负载。如果通过命令行自动化安装,请使用以下工作负载 ID:
vs_setup.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended
决策逻辑:目标平台配置 停止并询问用户: “您要为这个环境配置哪些目标平台?(A) Windows 桌面, (B) Android, 还是 (C) 两者?”
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
* **如果选择 (A) Windows 桌面:** 继续执行步骤 5。如果不需要,请禁用 Android 和 Web:
flutter config --no-enable-android
flutter config --no-enable-web
flutter config --enable-windows-desktop
* **如果选择 (B) Android:** 继续执行步骤 4。如果不需要,请禁用 Windows 桌面:
flutter config --no-enable-windows-desktop
* **如果选择 (C) 两者:** 执行步骤 4 和 5。确保两个平台都已启用。
4. 在 Windows 上配置 Android 工具
* 通过 SDK 管理器安装 Android Studio 和 Android SDK 命令行工具。
* 对于物理设备:在设备上启用“开发者选项”和“USB 调试”。为 Windows 安装 OEM USB 驱动程序。
* 对于模拟器:在 AVD 管理器中启用硬件加速,在“模拟性能”下选择“硬件”图形加速选项。
5. 构建和打包 Windows 桌面应用程序 要编译 Windows 应用程序,请执行:
flutter build windows
要手动打包应用程序,请从 build\windows\runner\Release\ 目录收集以下文件:
* 可执行文件 (`<project_name>.exe`)
* 所有 `.dll` 文件(例如 `flutter_windows.dll`)
* `data` 目录
* Visual C++ 可再发行组件(`msvcp140.dll`, `vcruntime140.dll`, `vcruntime140_1.dll`),将其放在 `.exe` 文件旁边。
可选: 要重命名生成的可执行文件,请修改 windows/CMakeLists.txt 中的 BINARY_NAME:
# Change this to change the on-disk name of your application.
set(BINARY_NAME "CustomAppName")
6. 为 MSIX 打包生成自签名证书 (OpenSSL) 如果用户需要本地测试 MSIX 包,请生成一个 .pfx 证书。确保 OpenSSL 在 PATH 中,然后执行:
openssl genrsa -out mykeyname.key 2048
openssl req -new -key mykeyname.key -out mycsrname.csr
openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000
openssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt
指导用户将 CERTIFICATE.pfx 安装到本地计算机证书存储的“受信任的根证书颁发机构”下。
验证与修复反馈循环 执行 Flutter 诊断工具以验证环境:
flutter doctor -v
* _条件:_ 如果报告 `cmdline-tools component is missing`,请指导用户打开 Android Studio -> 工具 -> SDK 管理器 -> SDK 工具,并勾选“Android SDK 命令行工具”。
* _条件:_ 如果报告 Visual Studio 工具链问题,请验证 `Microsoft.VisualStudio.Workload.NativeDesktop` 工作负载是否已完全安装。
* _条件:_ 如果 `flutter` 命令无法识别,请验证 PowerShell 的 `PATH` 注入是否成功,并重启终端进程。
C:\Program Files\)。flutter doctor 验证步骤;这是确认环境完整性的强制步骤。每周安装次数
803
代码仓库
GitHub 星标数
792
首次出现
2026年3月4日
安全审计
安装于
codex785
cursor782
gemini-cli781
opencode781
kimi-cli779
amp779
Configures a Windows development environment for building Flutter applications targeting Windows Desktop and Android. Analyzes system requirements, modifies environment variables, installs necessary C++ toolchains, manages platform-specific configurations, and generates self-signed certificates for local Windows application deployment. Assumes the host machine is running Windows 10 or 11 with administrative privileges available for system modifications.
Configure Flutter SDK and Environment Variables Extract the Flutter SDK to a secure, user-writable directory (e.g., C:\develop\flutter). Do not place it in C:\Program Files\. Execute the following PowerShell command to append the Flutter bin directory to the user's PATH:
$flutterBinPath = "C:\develop\flutter\bin"
$currentUserPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User)
if ($currentUserPath -notmatch [regex]::Escape($flutterBinPath)) {
[Environment]::SetEnvironmentVariable("Path", "$currentUserPath;$flutterBinPath", [EnvironmentVariableTarget]::User)
}
Install Windows Tooling To compile Windows desktop applications, Visual Studio (not VS Code) is strictly required. Install Visual Studio with the "Desktop development with C++" workload. If automating via command line, use the following workload ID:
vs_setup.exe --add Microsoft.VisualStudio.Workload.NativeDesktop --includeRecommended
Decision Logic: Target Platform Configuration STOP AND ASK THE USER: "Which target platforms are you configuring for this environment? (A) Windows Desktop, (B) Android, or (C) Both?"
If (A) Windows Desktop: Proceed to Step 5. Disable Android and Web if unnecessary:
flutter config --no-enable-android
flutter config --no-enable-web
flutter config --enable-windows-desktop
If (B) Android: Proceed to Step 4. Disable Windows desktop if unnecessary:
flutter config --no-enable-windows-desktop
If (C) Both: Execute Steps 4 and 5. Ensure both platforms are enabled.
Configure Android Tooling on Windows
Build and Package Windows Desktop Applications To compile the Windows application, execute:
flutter build windows
To package the application manually, gather the following files from build\windows\runner\Release\:
* The executable (`<project_name>.exe`)
* All `.dll` files (e.g., `flutter_windows.dll`)
* The `data` directory
* Visual C++ redistributables (`msvcp140.dll`, `vcruntime140.dll`, `vcruntime140_1.dll`) placed adjacent to the `.exe`.
Optional: To rename the generated executable, modify the BINARY_NAME in windows/CMakeLists.txt:
# Change this to change the on-disk name of your application.
set(BINARY_NAME "CustomAppName")
6. Generate Self-Signed Certificates for MSIX Packaging (OpenSSL) If the user requires local testing of an MSIX package, generate a .pfx certificate. Ensure OpenSSL is in the PATH, then execute:
openssl genrsa -out mykeyname.key 2048
openssl req -new -key mykeyname.key -out mycsrname.csr
openssl x509 -in mycsrname.csr -out mycrtname.crt -req -signkey mykeyname.key -days 10000
openssl pkcs12 -export -out CERTIFICATE.pfx -inkey mykeyname.key -in mycrtname.crt
Instruct the user to install CERTIFICATE.pfx into the local machine's Certificate Store under "Trusted Root Certification Authorities".
Validate-and-Fix Feedback Loop Execute the Flutter diagnostic tool to verify the environment:
flutter doctor -v
cmdline-tools component is missing is reported, instruct the user to open Android Studio -> Tools -> SDK Manager -> SDK Tools, and check "Android SDK Command-line Tools".Microsoft.VisualStudio.Workload.NativeDesktop workload is fully installed.flutter is not recognized, verify the PowerShell PATH injection succeeded and restart the terminal process.C:\Program Files\).flutter doctor validation step; it is mandatory for confirming environment integrity.Weekly Installs
803
Repository
GitHub Stars
792
First Seen
Mar 4, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex785
cursor782
gemini-cli781
opencode781
kimi-cli779
amp779
agent-browser 浏览器自动化工具 - Vercel Labs 命令行网页操作与测试
136,300 周安装