美文网首页我的Flutter倒霉之旅
我的Flutter倒霉之旅(五)

我的Flutter倒霉之旅(五)

作者: 雨落流年 | 来源:发表于2020-05-15 23:55 被阅读0次

    前言

    前面我们的flutter 最新稳定版本 flutter 1.17.1 已经成功在我们的设备上安家,但万事总有个万一,程序也是有些小脾气的,然后 就给你来了个bug调皮调皮,本文记录了 flutter 1.17.1启动的坑之 谷歌下载源被墙导致的启动报错
    (ps:如果你是第一次查看本篇文章,建议查看 我的flutter倒霉之旅专题)

    1. 启动报错之看看我见到的它

    FAILURE: Build failed with an exception.
    
    * What went wrong:
    Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
    > Could not resolve all task dependencies for configuration ':app:debugCompileClasspath'.
       > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         Required by:
             project :app
          > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
          > Could not resolve io.flutter:flutter_embedding_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/flutter_embedding_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/flutter_embedding_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
       > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         Required by:
             project :app
          > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
          > Could not resolve io.flutter:arm64_v8a_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/arm64_v8a_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/arm64_v8a_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
       > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         Required by:
             project :app
          > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
          > Could not resolve io.flutter:x86_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
       > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
         Required by:
             project :app
          > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Connection timed out: connect
          > Could not resolve io.flutter:x86_64_debug:1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.
             > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                > Could not HEAD 'https://storage.googleapis.com/download.flutter.io/io/flutter/x86_64_debug/1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664/x86_64_debug-1.0.0-fd60ddf7517ce2bfd6577636bda2065c0e492664.pom'.
                   > Connect to storage.googleapis.com:443 [storage.googleapis.com/34.64.4.80] failed: Read timed out
    
    

    该问题的解决办法为 更改flutter项目中android文件下的gradle配置以及flutter SDK中的 gradle 配置

    2. 更改配置

    在项目中 android 文件夹下的 build.gradle中注释原来的源,更改为以下源

    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public' }
    maven { url 'http://download.flutter.io' }
    
    更改示例

    打开你的flutter SDK 目录,依次打开 packages=>flutter_tools=>gradle文件夹,找到flutter.gradle文件,我这里使用vscode将其打开进行更改,将官方原来的配置项注释,方便改回,然后改为以下代码:

    maven { url 'https://maven.aliyun.com/repository/google' }
    maven { url 'https://maven.aliyun.com/repository/jcenter' }
    maven { url 'http://maven.aliyun.com/nexus/content/groups/public' } 
    // class flutter plugin中的更改
    private static final String MAVEN_REPO      = "https://storage.flutter-io.cn/download.flutter.io";
    
    更改示例

    3. 运行项目

    在项目根目录 运行 flutter run 或者使用 android studio的 run main.dart都可以,然后控制台无报错,项目成功运行在了 android studio 创建的模拟器上

    成功运行官方demo示例

    (本文适合初学者,如果你是大佬级别的人物,我也欢迎指教!)

    相关文章

      网友评论

        本文标题:我的Flutter倒霉之旅(五)

        本文链接:https://www.haomeiwen.com/subject/fuahohtx.html