Flutter 安装 Network resources 报错解决

安装过程中,运行: flutter doctor 提示: Network resources ✗ A cryptographic error occurred while checking "https://pub.dev/": Connection terminated during ha

安装过程中,运行:

flutter doctor

提示:

Network resources
    ✗ A cryptographic error occurred while checking "https://pub.dev/": Connection terminated during handshake
      You may be experiencing a man-in-the-middle attack, your network may be compromised, or you may have malware installed on your computer.

说明无法访问到"https://pub.dev/",有两种方式解决:

方法一:

修改以下路径的http_host_validator.dart文件:

{Flutter安装路径}\flutter\packages\flutter_tools\lib\src\http_host_validator.dart

找到其中常量的定义:

/// Common Flutter HTTP hosts.
const String kCloudHost = 'https://storage.googleapis.com/';
const String kCocoaPods = 'https://cocoapods.org/';
const String kGitHub = 'https://github.com/';
const String kMaven = 'https://maven.google.com/';
const String kPubDev = 'https://pub.dev/';

对应修改成国内的镜像网站即可,这里提供几个国内镜像地址:

pub.dev:        https://mirrors.tuna.tsinghua.edu.cn/dart-pub
kMaven:
        https://maven.aliyun.com/repository/google/

以下为修改方法:

CocoaPods:     https://mirrors.tuna.tsinghua.edu.cn/help/CocoaPods/
googleapis:
    改hosts,ip可以通https://tool.chinaz.com/speedtest/获取,选最快的就行

方法二:

将以上代码全部加入代理规则,以小猫的YAML举例:

- DOMAIN-SUFFIX,googleapis.com,🔰国外流量
- DOMAIN-SUFFIX,cocoapods.org,🔰国外流量
- DOMAIN-SUFFIX,pub.dev,🔰国外流量
        - DOMAIN-SUFFIX,google.com,🔰国外流量
        - DOMAIN-SUFFIX,github.com,🔰国外流量

LICENSED UNDER CC BY-NC-SA 4.0
Comment