1. Equipment environment
Windows11
Java11
2. Download Flutter3
download link:
https://docs.flutter.dev/get-started/install/windows
The version of Flutter I downloaded:
3. Modify the Path environment variable
Add the downloaded Flutter path to the system environment variable Path:
path-to-flutter/flutter/bin
4. Check Flutter doctor
- Mistake one:
Windows Version (Unable to confirm if installed Windows version is 10 or greater)
- Solution to error one:
# 切换flutter渠道
[1] 打开cmd
[2] 输入flutter channel 查看自己的flutter channel版本
[3] 输入flutter channel master,将flutter版本切换为master
[4] 输入flutter upgrade 确保flutter更新到了最新版本
[5] 输入 flutter doctor 再次检查是否解决
- Mistake 2:
Visual Studio not installed; this is necessary for Windows development
- Solution to error two:
下载Visual Studio,地址为:
https://visualstudio.microsoft.com/zh-hans/downloads/
下载完了之后进行安装,我选择了c++模块、和windows 10 SDK。
- Mistake three:
Android toolchain - develop for Android devices
- Solution to error three:
[1] 下载Android Studio,地址为:
https://developer.android.com/studio/index.html
[2] 通过 Android Studio 设置中的 SDK Tools 来安装 Command-line Tools(lastest)
[3] flutter config --android-sdk E:\environment\Android\Sdk
[4] flutter doctor --android-licenses
- Mistake four:
[!] Network resources
HTTP Host Availability
X A network error occurred while checking "https://pub.dev/": 信号灯超时时间已到
X An HTTP error occurred while checking "https://github.com/": 信号灯超时时间已到
- Solution to error four:
错误提示如下,分析可知是 maven.google.com 访问失败造成的:
HTTP host https://maven.google.com/ is not reachable. Reason: An error occurred while checking the HTTP host: Operation timed out
[1] 打开path-to-flutter-sdk/packages/flutter_tools/lib/src/http_host_validator.dart文件,修改https://maven.google.com/为 google maven 的国内镜像,如https://dl.google.com/dl/android/maven2/
[2] 设置系统环境变量
FLUTTER_STORAGE_BASE_URL -> https://storage.flutter-io.cn
PUB_HOSTED_URL -> https://pub.flutter-io.cn
[3] 去到flutter\bin\cache目录,删除flutter_tools.snapshot文件。请不要删除cache文件夹,不然需要下载很多东西。
[4] 重新执行flutter doctor
5. Environment completed
6. Configuration modified by yourself (for reference only)
- Modify flutter.gradle
flutter\packages\flutter_tools\gradle\flutter.gradle
原来:
private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
修改:
// private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
private static final String DEFAULT_MAVEN_HOST = "https://storage.flutter-io.cn";
- In the project, modify android/build.gradle
buildscript {
ext.kotlin_version = '1.7.10'
repositories {
// google()
// mavenCentral()
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/google'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
dependencies {
classpath 'com.android.tools.build:gradle:7.3.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
// google()
// mavenCentral()
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/google'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/repositories/jcenter'
}
maven {
allowInsecureProtocol = true
url 'http://maven.aliyun.com/nexus/content/groups/public/'
}
}
}
rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}
tasks.register("clean", Delete) {
delete rootProject.buildDir
}