Flutter安装踩坑记录

安装Flutter SDK

  1. Windows安装
    flutter官网下载flutter sdk包

2.解压到C盘除去program file相关的目录(最好自己创建一个新的目录,因为放在program file等目录需要特殊的权限,会出现问题)

  1. Android 需要安装Android SDK ,同理苹果开发也需要对应的环境

  2. 安装ide工具(Android Studio ,visual studio code)都可以

  3. 运行 flutter doctor检查安装环境

PS C:\Android\flutter\bin> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19042.1645], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 30.0.0-preview)
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Enterprise 2022 17.1.0)
    X Visual Studio is missing necessary components. Please re-run the Visual Studio installer for the "Desktop
      development with C++" workload, and include these components:
        MSVC v142 - VS 2019 C++ x64/x86 build tools
         - If there are multiple build tool versions available, install the latest
        C++ CMake tools for Windows
        Windows 10 SDK
[√] Android Studio (version 2021.1)
[√] VS Code, 64-bit edition (version 1.66.1)
[√] Connected device (3 available)
[!] HTTP Host Availability
    X HTTP host https://maven.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host:
      Failed host lookup: 'maven.google.com'
    X HTTP host https://pub.dev/ is not reachable. Reason: An error occurred while checking the HTTP host: Failed host
      lookup: 'pub.dev'
    X HTTP host https://cloud.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host:
      Failed host lookup: 'cloud.google.com'

! Doctor found issues in 3 categories.

flutter doctor
提示错误
-Waiting for another flutter command to release the startup lock...
- 看到任务管理器里面有9个dart服务在运行,因此删除不了 flutter 安装目录下的bin/cache/lockfile文件,可以使用下面的命令停止dart服务的运行

// Linux
killall -9 dart

// Windows
taskkill /F /IM dart.exe

C:\WINDOWS\system32>taskkill /F /IM dart.exe
SUCCESS: The process "dart.exe" with PID 58904 has been terminated.
SUCCESS: The process "dart.exe" with PID 59660 has been terminated.
SUCCESS: The process "dart.exe" with PID 64856 has been terminated.
SUCCESS: The process "dart.exe" with PID 64820 has been terminated.
SUCCESS: The process "dart.exe" with PID 69264 has been terminated.
SUCCESS: The process "dart.exe" with PID 65924 has been terminated.
SUCCESS: The process "dart.exe" with PID 61544 has been terminated.
SUCCESS: The process "dart.exe" with PID 68612 has been terminated.
SUCCESS: The process "dart.exe" with PID 66868 has been terminated.
SUCCESS: The process "dart.exe" with PID 55608 has been terminated.
SUCCESS: The process "dart.exe" with PID 67136 has been terminated.
SUCCESS: The process "dart.exe" with PID 73776 has been terminated.
  • HTTP host https://maven.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host: Failed host lookup: 'maven.google.com'
    - 替换flutter\packages\flutter_tools\lib\src\http_host_validator.dart 目录下的 'maven.google.com''https://dl.google.com/dl/android/maven2/'
    - 关闭所有命令行窗口,再打开命令行窗口
    - 去到flutter\bin目录,删除cache文件夹
    - 重新运行flutter doctor
Could not resolve URL "https://pub.flutter-io.cn".
pub get failed (server unavailable) -- attempting retry

powershell中运行

setx PUB_HOSTED_URL "https://pub.flutter-io.cn"
setx FLUTTER_STORAGE_BASE_URL "https://storage.flutter-io.cn"

参考链接

如何解决“Waiting for another flutter command to …”
[转]Windows构建Flutter环境,无法访问maven.google.com
Step by step setting up flutter and pub mirrors in china using Windows Operating System #46641
【flutter】pub get failed (server unavailable) – attempting解决办法
vscode 安装flutter遇到的坑

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐