flutter 运行构建时速度过慢以及运行错误

重新运行时建议先清空项目的缓存文件

flutter clean

运行命令查看下载进度详情

flutter run -v

通常情况下在下载 gradle.zip 包时会连接超时或者失败,因 gradle 的远程仓库在国外会受到墙的影响,国内一些文章建议更换镜像源实测后无效

报错信息

[ +152 ms] Downloading https://services.gradle.org/distributions/gradle-7.5-all.zip
[+22995 ms] Exception in thread "main" java.net.ConnectException: Connection timed out: connect

解决方法

手动下载 gradle-7.5-all.zip 包,将压缩包可放到 C:/Users/15031/.gradle/wrapper/dists/ 目录下, 适用于所有gradle超时情况

在项目目录中找到 android/dradle/wrapper/gradle-wrapper.properties 配置文件

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
#distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
/**替换*/
distributionUrl=file\:///C:/Users/UserName/.gradle/wrapper/dists/gradle-7.5-all.zip

然后重新运行flutter run 会默认从本地包中就加载相应文件


报错信息二

当运行时报 Users/UserName/.gradle/wrapper/dists/gradlexxx 时,可将 .gradle 目录删除,运行 flutter 项目时会重新构建改文件,但构建该目录时可能需要花费一些时间


场景二 完成上方配置后运行仍然较慢,可尝试修改 gradle 镜像

配置路径 android/build.gradle,如下完整配置示例

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
    	// 注释掉
        // google()
        // mavenCentral()
        // 换成阿里镜像源
        maven {
            allowInsecureProtocol = true
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            allowInsecureProtocol = true
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/groups/public'
        }
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
    	// 操作同上
        // google()
        // mavenCentral()
        maven {
            allowInsecureProtocol = true
            url 'https://maven.aliyun.com/repository/google'
        }
        maven {
            allowInsecureProtocol = true
            url 'https://maven.aliyun.com/repository/jcenter'
        }
        maven {
            allowInsecureProtocol = true
            url 'http://maven.aliyun.com/nexus/content/groups/public'
        }
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇