解决 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

结束语

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

相关推荐
Zender Han6 小时前
Flutter 视频播放器——flick_video_player 介绍与使用
android·flutter·ios·音视频
恋猫de小郭11 小时前
Flutter Riverpod 3.0 发布,大规模重构下的全新状态管理框架
android·前端·flutter
RaidenLiu12 小时前
Riverpod 3:重建控制的实践与性能优化指南
前端·flutter
蒋星熠1 天前
Flutter跨平台工程实践与原理透视:从渲染引擎到高质产物
开发语言·python·算法·flutter·设计模式·性能优化·硬件工程
卢叁1 天前
Flutter之自定义TabIndicator
前端·flutter
萧雾宇1 天前
Android Compose打造仿现实逼真的烟花特效
android·flutter·kotlin
拜无忧1 天前
【教程】flutter常用知识点总结-针对小白
android·flutter·android studio
拜无忧1 天前
【教程】Flutter 高性能项目架构创建指南:从入门到高性能架构
android·flutter·android studio
醉过才知酒浓1 天前
flutter 拦截返回按钮的方法(WillPopScope or PopScope)
flutter
傅里叶2 天前
sudo启动Flutter程序AMD初始化失败
linux·flutter