flutter开发的一个小小小问题,内网依赖下不来

问题

由于众所周知的原因,flutter编译时,经常出现Could not get resource 'https://storage.googleapis.com/download.flutter.io...'的问题,如下:

bash 复制代码
* What went wrong:
Could not determine the dependencies of task ':app:lintVitalRelease'.
> Could not resolve all artifacts for configuration ':app:debugCompileClasspath'.
   > Could not download armeabi_v7a_debug-1.0.0-cdbeda788a293fa29665dc3fa3d6e63bd221cb0d.jar (io.flutter:armeabi_v7a_debug:1.0.0-cdbeda788a293fa29665dc3fa3d6e63bd221cb0d)
      > Could not get resource 'https://storage.googleapis.com/download.flutter.io/io/flutter/armeabi_v7a_debug/1.0.0-cdbeda788a293fa29665dc3fa3d6e63bd221cb0d/armeabi_v7a_debug-1.0.0-cdbeda788a293fa2966
5dc3fa3d6e63bd221cb0d.jar'.
         > Could not GET 'https://storage.googleapis.com/download.flutter.io/io/flutter/armeabi_v7a_debug/1.0.0-cdbeda788a293fa29665dc3fa3d6e63bd221cb0d/armeabi_v7a_debug-1.0.0-cdbeda788a293fa29665dc3fa
3d6e63bd221cb0d.jar'.
            > Connection reset

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 5s
Running Gradle task 'assembleRelease'...                            6.4s
[!] Gradle threw an error while downloading artifacts from the network.
Retrying Gradle Build: #12, wait time: 204800ms

解决

修改flutter中gradle的仓库配置,目录为:D:\google\flutter\packages\flutter_tools\gradle

打开flutter.gradle,然后修改仓库信息为:http://mirror.nju.edu.cn/flutter,如下:

java 复制代码
    // private static final String DEFAULT_MAVEN_HOST = "https://storage.googleapis.com";
    private static final String DEFAULT_MAVEN_HOST = "http://mirror.nju.edu.cn/flutter";

分析

然后,我又看了下flutter.gradle里面的代码,给大家看看:

java 复制代码
        // Configure the Maven repository.
        String hostedRepository = System.env.FLUTTER_STORAGE_BASE_URL ?: DEFAULT_MAVEN_HOST
        String repository = useLocalEngine()
            ? project.property('local-engine-repo')
            : "$hostedRepository/download.flutter.io"
        rootProject.allprojects {
            repositories {
                maven {
                    url repository
                }
            }
        }

真是自作孽不可活,明明有FLUTTER_STORAGE_BASE_URL这个环境变量可以去设置,自己懒不设置,活该!

快捷

跟我一样懒惰的兄弟们,给你们把链接奉上,https://docs.flutter.dev/community/china

自取,去设置环境变量,别懒得一坨耙耙一样了!!!

相关推荐
鸣弦artha1 天前
Flutter框架跨平台鸿蒙开发——Widget体系概览
flutter·华为·harmonyos
南村群童欺我老无力.1 天前
Flutter 框架跨平台鸿蒙开发 - 打造安全可靠的密码生成器,支持强度检测与历史记录
flutter·华为·typescript·harmonyos
鸣弦artha1 天前
Flutter 框架跨平台鸿蒙开发——Flutter引擎层架构概览
flutter·架构·harmonyos
时光慢煮1 天前
基于 Flutter × OpenHarmony 图书馆管理系统之构建搜索栏
flutter·华为·开源·openharmony
kirk_wang1 天前
Flutter艺术探索-Flutter生命周期:State生命周期详解
flutter·移动开发·flutter教程·移动开发教程
鸣弦artha1 天前
Flutter框架跨平台鸿蒙开发——Build流程深度解析
开发语言·javascript·flutter
鸣弦artha1 天前
Flutter框架跨平台鸿蒙开发——StatelessWidget基础
flutter·华为·harmonyos
时光慢煮1 天前
基于 Flutter × OpenHarmony 图书馆管理系统之构建模块选择器(底部导航栏样式)
flutter·开源·openharmony
夜雨声烦丿1 天前
Flutter 框架跨平台鸿蒙开发 - 打造习惯打卡应用,连续天数统计与热力图展示
flutter·华为·harmonyos
2401_882351521 天前
Flutter for OpenHarmony 商城App实战 - 地址编辑实现
android·java·flutter