Featured image of post Windows搭建Flutter开发环境

Windows搭建Flutter开发环境

此文记录一下配置FLutter环境的步骤(防止自己忘记)

STEP 1: Java SDK

这里我使用的是jdk-17.0.8,官网地址Java Archive Downloads - Java SE 17 ,选择并下载Windows x64 Compressed Archive,如图:

解压至你想安装的目录下,在环境变量中添加变量名JAVA_HOME,值为D:\Path\to\jdk-17.0.8\,在环境变量Path中添加值%JAVA_HOME%\bin\

cmd中运行java --version,若返回版本信息,则表明配置成功。

1
2
3
4
C:\Users\root>java --version
openjdk 17.0.8 2023-07-18 LTS
OpenJDK Runtime Environment Microsoft-8035246 (build 17.0.8+7-LTS)
OpenJDK 64-Bit Server VM Microsoft-8035246 (build 17.0.8+7-LTS, mixed mode)

STEP 2: Flutter SDK

从Flutter官网Archive | Flutter 或者GithubReleases · flutter/flutter 获取Flutter,解压至你想安装的目录下,在环境变量Path中添加值D:\Path\to\Flutter\bin\,在cmd中运行flutter --version,若返回版本信息,则表明配置成功。

1
2
3
4
5
C:\Users\root>flutter --version
Flutter 3.24.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 2663184aa7 (6 weeks ago) • 2024-09-11 16:27:48 -0500
Engine • revision 36335019a8
Tools • Dart 3.5.3 • DevTools 2.37.3

( optional ) For some known reasons, you can configure mirrors to access Flutter packages:

Add two entries to your environment variables:

  • Name: PUB_HOSTED_URL Value: https://pub.flutter-io.cn
  • Name: FLUTTER_STORAGE_BASE_URL Value: https://storage.flutter-io.cn

STEP 3: Android SDK

下载地址:下载 Android Studio 和应用工具 - Android 开发者 | Android Developers

获取后解压至你想安装的目录下,这里以D:\Android-SDK为例,下载后将cmdline-tools内的所有文件放在D:\Android-SDK\cmdline-tools\latest\目录下,如图:

D:\Android-SDK\cmdline-tools\latest\bin\目录下打开cmd,输入sdkmanager --list,若返回列表,则表示配置成功。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
D:\Android-SDK\cmdline-tools\latest\bin>sdkmanager --list
Warning: Errors during XML parse:
Warning: Additionally, the fallback loader failed to parse the XML.
[=======================================] 100% Computing updates...

Available Packages:
  Path                                                                            | Version           | Description     
  -------                                                                         | -------           | -------         
  add-ons;addon-google_apis-google-15                                             | 3                 | Google APIs     
  add-ons;addon-google_apis-google-16                                             | 4                 | Google APIs     
  add-ons;addon-google_apis-google-17                                             | 4                 | Google APIs     

............

下载你需要的平台以及工具,还是在D:\Android-SDK\cmdline-tools\latest\bin\目录下打开cmd,输入sdkmanager “platform-tools” “platforms;android-34”安装platform-tools,输入sdkmanager “build-tools;34.0.0”安装build-tools。(这里你可以自行在刚刚的列表中选择你需要的平台和工具)

STEP 4: Visual Studio

安装Visual Studio,官网地址:下载 Visual Studio Tools - 免费安装 Windows、Mac、Linux ,可以选择社区版,在安装界面勾选使用C++的桌面开发选项,在安装位置界面,根据需要选择是否修改IDE、缓存、SDK的存放路径。

STEP 5: Android Studio

从官网获取并安装Android Studio,地址:下载 Android Studio 和应用工具 - Android 开发者 | Android Developers

( optional ) Android Studio汉化:从Jetbrains下载中文语言包,地址:Chinese (Simplified) Language Pack / 中文语言包 Plugin for JetBrains IDEs | JetBrains Marketplace ,下载后在Android Studio的插件页面导入本地插件,选择下载的中文语言包,导入成功后重启IDE即可完成汉化。

STEP 6: Flutter Configure

新增环境变量ANDRIOD_HOME,值为Android SDK安装目录,如D:\Android-SDK\,在Path中添加三个值:%ANDROID_HOME%\tools%ANDROID_HOME%\platform-tools%ANDROID_HOME%\build-tools,在cmd中运行flutter config --android-sdk D:\Android-SDK\ ,向flutter指定Android SDK目录。

检查flutter配置:在cmd中运行flutter doctor ,查看各项配置是否正确。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
C:\Users\root>flutter doctor
Flutter assets will be downloaded from https://storage.flutter-io.cn. Make sure you trust this source!
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.24.3, on Microsoft Windows [版本 10.0.19045.5011], locale zh-CN)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.11.5)
[√] Android Studio (version 2024.1)
[√] Connected device (3 available)
[√] Network resources

• No issues found!

配置完成后,在Android Studio安装flutterdart插件,开始Flutter APP的开发。

参考文档

1.3 搭建Flutter开发环境 | 《Flutter实战·第二版》

Licensed under CC BY-NC-SA 4.0
本博客已运行
发表了6篇文章 · 总计11.99k字
使用 Hugo 构建
主题 StackJimmy 设计