在flutter官网下载flutter
在 Windows 操作系统上安装和配置 Flutter 开发环境 - Flutter 中文文档 - Flutter 中文开发者网站 - Flutter
下载文件后,解压文件把文件存放在指定位置
打开flutter_console.bat文件
输入flutter doctor
flutter报错提示(一)
执行flutter doctor 提示 Windows Version (Unable to confirm if installed Windows version is 10 or greater)
Windows Version (Unable to confirm if installed Windows version is 10 or greater)
把该目录下的文件替换为下面的代码
flutter\packages\flutter_tools\lib\src\windows\windows_version_validator.dart
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:process/process.dart';
import '../base/io.dart';
import '../doctor_validator.dart';
// FIX #1 - Remove everything from line 10 to 20 in original source code.
/// Validator for supported Windows host machine operating system version.
class WindowsVersionValidator extends DoctorValidator {
const WindowsVersionValidator({required ProcessManager processManager})
: _processManager = processManager,
super('Windows Version');
final ProcessManager _processManager;
@override
Future<ValidationResult> validate() async {
// FIX #2 - Replace 'systeminfo' by 'ver' command
final ProcessResult result =
await _processManager.run(<String>['ver'], runInShell: true);
if (result.exitCode != 0) {
return const ValidationResult(
ValidationType.missing,
<ValidationMessage>[],
statusInfo: 'Exit status from running `systeminfo` was unsuccessful',
);
}
final String resultStdout = result.stdout as String;
// FIX #3 - Remove brackets from output
final String resultAdjusted = resultStdout.replaceAll('[','').replaceAll(']','');
// FIX #4 - Split the output at spaces, and get Windows version at position 3.
// Split again at dots and get the major version at position 0.
// Cast the output to int.
final int winver = int.parse(resultAdjusted.split(' ').elementAt(3).split('.').elementAt(0));
// Use the string split method to extract the major version
// and check against the [kUnsupportedVersions] list
final ValidationType windowsVersionStatus;
final String statusInfo;
// FIX #5 - Check if Windows major version is greater than 10.
// Succeeds if true.
if (winver >= 10) {
windowsVersionStatus = ValidationType.installed;
statusInfo = 'Installed version of Windows is version 10 or higher';
} else {
windowsVersionStatus = ValidationType.missing;
statusInfo =
'Unable to confirm if installed Windows version is 10 or greater';
}
return ValidationResult(
windowsVersionStatus,
const <ValidationMessage>[],
statusInfo: statusInfo,
);
}
}
删除文件 flutter\bin\cache\flutter_tools.stamp/ (不删除也可以,先执行flutter doctor如果报错再删除文件)
flutter报错提示(二)
执行flutter doctor 提示[X] Android toolchain - develop for Android devices
[X] Android toolchain - develop for Android devices
X Unable to locate Android SDK.
Install Android Studio from: https://developer.android.com/studio/index.html
On first launch it will assist you in installing the Android SDK components.
(or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
If the Android SDK has been installed to a custom location, please use
`flutter config --android-sdk` to update to that location.
打开Android Studio 右上角 打开设置
打开Android SDK 右上角显示Android SDK Location 会显示存放的SDK路径
如果没有显示 点击Android SDK Location 后的提示,根据提示操作
执行
flutter config --android-sdk C:\Users\zhangmj2\AppData\Local\Android\Sdk
Setting "android-sdk" value to "C:\Users\zhangmj2\AppData\Local\Android\Sdk".
flutter报错提示(三)
执行flutter doctor 提示[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
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.
需要执行flutter doctor --android-licenses
flutter doctor --android-licenses
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this.
执行flutter doctor --android-licenses后提示
Android sdkmanager not found. Update to the latest Android SDK and ensure that the cmdline-tools are installed to resolve this.
打开Android Studio 右上角 打开设置 选择Android SDK
选择完成后自动下载
安装完成后再次执行flutter doctor --android-licenses
无报错后执行flutter doctor
flutter报错提示(四)
执行flutter doctor 提示需要安装Visual Studio 如果不需要开发,可以不用安装
[X] Visual Studio - develop for Windows
X Visual Studio not installed; this is necessary for Windows development.
Download at https://visualstudio.microsoft.com/downloads/.
Please install the "Desktop development with C++" workload, including all of its default components
flutter提示报错(五)
执行flutter doctor 提示 X HTTP host “https://maven.google.com/” is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到
HTTP Host availability check is taking a long time...[!] HTTP Host Availability
X HTTP host "https://maven.google.com/" is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到
X HTTP host "https://cloud.google.com/" is not reachable. Reason: An error occurred while checking the HTTP host: 信号灯超时时间已到
在flutter安装路径下找到flutter/packages/flutter_tools/lib/src/http_host_validator.dart文件
将https://maven.google.com/ 修改为https://dl.google.com/dl/android/maven2/
并打开flutter\bin\cache 删除flutter_tools.snapshot文件,永久删除。
再次运行flutter doctor文章来源:https://www.toymoban.com/news/detail-431242.html
文章来源地址https://www.toymoban.com/news/detail-431242.html
到了这里,关于windows安装flutter的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!