• windows下flutter的环境安装


    Flutter是谷歌出品的移动应用SDK,性能卓越、体验精美、跨平台、HotReload等等这些特点。

    Dart是谷歌推出的编程语言。支持即时编译JIT(Just In Time)、HotReload(热加载)和事前编译AOT(Ahead of Time)。

    所以搜索语法要用dart

    一、下载

    • git下载:https://git-scm.com/download/win
    • android studio: https://developer.android.google.cn/studio
    • Flutter SDK:https://docs.flutter.dev/get-started/install

    二、环境变量

    PUB_HOSTED_URL=https://pub.flutter-io.cn
    FLUTTER_STORAGE_BASE_URL=https://storage.flutter-io.cn
    
    注意:这两个环境变量一定要加,否则可能导致后面 flutter doctor 命令连接不上服务
    
    • 1
    • 2
    • 3
    • 4

    三、安装

    安装git

    安装android studio

    会让你下载SDK,记一下路径,然后配置到环境变量中。

    ANDROID_HOME = Android sdk路径
    
    • 1

    如果忘记了或者没记或者跳过了安装安卓SDK的步骤:

    Alt text

    Alt text

    安装Flutter SDK

    把之前下载的SDK直接解压。
    比如我的是:C:\sdk\flutter

    然后把bin目录配置到环境变量中:

    C:\sdk\flutter\bin
    
    • 1

    Alt text

    打开cmd检测下:

    flutter --version 查看是否安装成功
    flutter -h  能够展示指令,表示安装配置成功
    
    • 1
    • 2

    四、flutter doctor 环境检测

    在前面都安装完后,才是正式安装的开始。

    打开cmd,运行 flutter doctor
    Alt text

    这是运行成功的例子,那么哪个不对改哪里。

    4.1 安卓SDK下载不了

    AppData\\Roaming\\Google 下缓存删掉

    4.2 HTTP Host availability check is taking a long time…

    img

    1. 找到flutter sdk的文件目录,依次找到flutter/packages/flutter_tools/lib/src/http_host_validator.dart文件
    2. https://maven.google.com/ 修改为https://dl.google.com/dl/android/maven2/
    3. 关闭所有打开了flutterSDK的程序,找到flutter\bin目录下的flutter_tools.snapshot文件,删除。
    4. 重新打开cmd,再试。(注意要重新打开)

    4.3 Windows Version (Unable to confirm if installed Windows version is 10 or greater)

    1. 打开:\packages\flutter_tools\lib\src\windows\windows_version_validator.dart
    2. 直接替换:
    // 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;
    
      
      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,
        );
      }
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    1. 删除文件:\bin\cache\flutter_tools.stamp
    2. 重新打开cmd,再试。(注意要重新打开)

    4.4 如果不在PC上运行,Visual Studio 不用管。

    4.5 android-licenses

    这个是需要同意一下协议。

    flutter doctor --android-licenses
    然后全部同意就行了。
    
    • 1
    • 2

    五、使用

    5.1 找不到dart sdk

    C:\\sdk\\flutter\\bin\\cache\\dart-sdk
    
    • 1

    5.2 卡在Running Gradle task ‘assembleDebug’

    属于网络问题,国内对一些镜像是有墙的,换一下就行。你自己翻也行。

    1. 打开flutter\packages\flutter_tools\gradle\flutter.gradle
    2. 改:
    private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
    
    改成:
    
    "https://storage.flutter-io.cn";
    
    • 1
    • 2
    • 3
    • 4
    • 5
    buildscript {
        repositories {
            maven { url 'https://maven.aliyun.com/repository/google' }
            maven { url 'https://maven.aliyun.com/repository/jcenter' }
            maven { allowInsecureProtocol = true
                url 'http://maven.aliyun.com/nexus/content/groups/public' }
            //google()
            //mavenCentral()
        }
    
        dependencies {
            classpath 'com.android.tools.build:gradle:7.2.0'
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    
    allprojects {
        repositories {
            maven { url 'https://maven.aliyun.com/repository/google' }
            maven { url 'https://maven.aliyun.com/repository/jcenter' }
            maven { allowInsecureProtocol = true
                url 'http://maven.aliyun.com/nexus/content/groups/public' }
            //google()
            //mavenCentral()
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    1. 重新编译运行即可。

    项目文件中android/build.gradle也有相关配置,改一下也可以,即只对项目生效。

    5.3 Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven…

    这是因为上一个问题中:allowInsecureProtocol = true没有加,或者路径没有加https。

    六、总结

    Flutter使用的是谷歌生态,所以有很多网络不通的情况,如果编译卡住了,可以首先怀疑是网络墙了。

    这是我个人安装过程中的一些问题,如果还有其他问题,欢迎评论补充。如果有不对的,或者试了没有效果的,也欢迎指正。

  • 相关阅读:
    主线程结束子线程不再执行
    python处理三调缩编数据第二步不同类型融合
    详解AUTOSAR:AUTOSRA软件架构(理论篇—2)
    关于缓存的一些问题
    代码随想录算法训练营 动态规划part09
    让她/他心动的520/521告白方法(9个方法+链接+代码,原生HTML+CSS+JS实现)
    如何将WPS设置为默认的办公软件
    SpringCloud Gateway基于nacos实现动态路由
    【毕业设计】基于深度学习卷积神经网络的手势识别算法 - python opencv 机器视觉
    06【保姆级】-GO语言的运算符
  • 原文地址:https://blog.csdn.net/happy_teemo/article/details/132831726