一、安装git环境和node环境,之前就已经安装,不赘述,图上放下版本:
二、配置JAVA环境(exe文件)Java JDK
其他低版本下载地址(所有低版本列表)
这里用的17版,下载地址
.exe安装之后配置环境变量:电脑—右键—高级设置—环境变量
1.新建用户环境变量JAVA_HOME,变量值是jdk的地址
2.然后进入用户变量中的Path,点击“编辑”,新建以下path,即“%JAVA_HOME%\bin”,如下图:
3.测试JDK是否配置成功,打开powerShell命令 (注意:一定要重新打开,不能用在配置Java环境变量前打开的),然后输入命令“java --version”,如果能够成功显示JDK版本信息,则说明JDK配置成功。
三、安装flutter
下载flutter SDK 选稳定版本,解压之后放到某个盘,我这里放到D:\program file
配置flutter环境变量
1.电脑—右键—高级设置—环境变量—粘贴下面flutter/bin目录地址
D:\program file\flutter\bin
D:\program file\flutter\bin \cache\dart-sdk
四、配置安卓环境
安卓环境需要安装android studio
下载flutter插件:
安装安卓之后—打开—选右下角plugins—输入flutter并搜索—进行安装—重启
五、powerShell命令输入“flutter doctor”命令查看flutter安装情况,报错信息逐个排查解决
1.cmdline-tools component is missing
打开AndroidStudio右上角设置—》操作下图的勾选项点下载图标--》点OK去下载
2.Android license status unknown
安装证书,命令:flutter doctor --android-licenses(报错信息里有,拷贝执行即可),一步步提示y/n全部选y
3.Visual Studio - develop Windows apps
4.解决Google USB Driver
终端执行 flutter devices
六、安装gradle(依赖仓库,打包工具,需要jdk版本8以上)
下载地址这里用7.5版本,将下载的文件解压到本地目录,如:D:\gradle-7.5
1.配置环境变量
2.配置打包下载地址变量(下载到D:\gradle,要不然默认给放C盘)
七、以上操作完成,现在执行fluttler doctor会报下面的错误
1.做个镜像
在D:\gradle(对应上面六-2的信息资源包地址/文件打包下载地址)新建一个文件,名字:init.gradle
。
主要功能是将一些默认的Maven仓库替换为阿里云的镜像仓库,以加速依赖的下载速度,内容如下:
allprojects{
repositories {
def ALIYUN_REPOSITORY_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_JCENTER_URL = 'https://maven.aliyun.com/repository/public'
def ALIYUN_GOOGLE_URL = 'https://maven.aliyun.com/repository/google'
def ALIYUN_GRADLE_PLUGIN_URL = 'https://maven.aliyun.com/repository/gradle-plugin'
all { ArtifactRepository repo ->
if(repo instanceof MavenArtifactRepository){
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_JCENTER_URL."
remove repo
}
if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GOOGLE_URL."
remove repo
}
if (url.startsWith('https://plugins.gradle.org/m2/')) {
project.logger.lifecycle "Repository ${repo.url} replaced by $ALIYUN_GRADLE_PLUGIN_URL."
remove repo
}
}
}
maven { url ALIYUN_REPOSITORY_URL }
maven { url ALIYUN_JCENTER_URL }
maven { url ALIYUN_GOOGLE_URL }
maven { url ALIYUN_GRADLE_PLUGIN_URL }
}
}
代码里的镜像地址都是阿里云的,可参考:阿里云镜像文档,也可以换成其他家的镜像地址
2.执行flutter doctor,会报:无法访问https://maven.google.com
(1)进入flutter sdk的目录,打开D:\Program Files\flutter\packages\flutter_tools\lib\src \http_host_validator.dart
(2)将https://maven.google.com/修改https://maven.aliyun.com/repository/google/
(3)去到flutter\bin目录,删除 cache 目录下的 flutter_tools.snapshot 文件
3.在cmd命令窗口重新运行flutter doctor此时会报A network error occurred while checking“https://github.com/“
将以下全部复制粘贴到C:\Windows\System32\drivers\etc\hosts里面保存之后。
192.30.253.113 github.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.237.1 dl-ssl.google.com
173.194.127.200 groups.google.com
192.30.252.131 github.com
185.31.16.185 github.global.ssl.fastly.net
74.125.128.95 ajax.googleapis.com
192.30.255.112 github.com git
185.31.16.184 github.global.ssl.fastly.net
192.30.253.112 github.com
192.30.253.119 gist.github.com
151.101.184.133 assets-cdn.github.com
151.101.184.133 raw.githubusercontent.com
151.101.184.133 gist.githubusercontent.com
151.101.184.133 cloud.githubusercontent.com
151.101.184.133 camo.githubusercontent.com
151.101.184.133 avatars0.githubusercontent.com
151.101.184.133 avatars1.githubusercontent.com
151.101.184.133 avatars2.githubusercontent.com
151.101.184.133 avatars3.githubusercontent.com
151.101.184.133 avatars4.githubusercontent.com
151.101.184.133 avatars5.githubusercontent.com
151.101.184.133 avatars6.githubusercontent.com
151.101.184.133 avatars7.githubusercontent.com
151.101.184.133 avatars8.githubusercontent.com
再次运行flutter doctor。