解决 Flutter assemble 长时间卡死后失败问题

软件环境

Flutter 3.19.5 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 300451adae (2 weeks ago) • 2024-03-27 21:54:07 -0500
Engine • revision e76c956498
Tools • Dart 3.3.3 • DevTools 2.31.1

解决方法

需要修改项目中两个文件:

  • gradle/wrapper/gradle-wrapper.properties
  • build.gradle (注意:不是 app/build.gradle)

分别修改这两个文件内的 distributionUrl 路径和仓库地址。

修改 gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-x.x.x-all.zip​ 修改为 distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-x.x.x-all.zip​。

也就是将 gradle url 的部分路径 https\://services.gradle.org/distributions/​ 修改为 https\://mirrors.cloud.tencent.com/gradle/​。

以 gradle-7.6.3-all.zip 为例,distributionUrl 修改后的结果如下:

properties 复制代码
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

#distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
distributionUrl=https\://mirrors.cloud.tencent.com/gradle/gradle-7.6.3-all.zip
修改 build.gradle

repositories​ 添加阿里仓库:

properties 复制代码
maven{ url 'https://maven.aliyun.com/repository/google'}
maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
maven{ url 'https://maven.aliyun.com/repository/public'}
maven{ url 'https://maven.aliyun.com/repository/jcenter'}

修改后的结果:

properties 复制代码
allprojects {        
    repositories {        
        maven{ url 'https://maven.aliyun.com/repository/google'}
        maven{ url 'https://maven.aliyun.com/repository/gradle-plugin'}
        maven{ url 'https://maven.aliyun.com/repository/public'}
        maven{ url 'https://maven.aliyun.com/repository/jcenter'}
        google()        
        mavenCentral()        
    }
}

参考文章

https://blog.csdn.net/afunx/article/details/129913028

结束语

本文如有偏颇,恳请斧正。

相关推荐
lqj_本人1 天前
flutter_鸿蒙next_Dart基础②List
flutter
lqj_本人1 天前
flutter_鸿蒙next_Dart基础①字符串
flutter
The_tuber_sadness1 天前
【Flutter】- 基础语法
flutter
helloxmg1 天前
鸿蒙harmonyos next flutter通信之BasicMessageChannel获取app版本号
flutter
linpengteng2 天前
使用 Flutter 开发数字钱包应用(Dompet App)
前端·flutter·firebase
云兮Coder2 天前
鸿蒙 HarmonyNext 与 Flutter 的异同之处
flutter·华为·harmonyos
lqj_本人2 天前
flutter_鸿蒙next(win)环境搭建
flutter·华为·harmonyos
yuanlaile3 天前
Windows上面搭建Flutter Android运行环境
android·flutter