解决Flutter项目中Gradle构建Running Gradle task ‘assembleDebug‘卡顿问题的终极指南

解决Flutter项目中Gradle构建Running Gradle task ‘assembleDebug‘卡顿问题的终极指南

前言

在开发Flutter应用时,经常会遇到Gradle构建卡在Running Gradle task 'assembleDebug'阶段的问题。本文将分享如何通过配置华为云镜像和使用自定义脚本下载依赖的方法解决这些问题。

问题描述

典型错误如下:

FAILURE: Build failed with an exception.

* Where:
Settings file 'android/settings.gradle.kts' line: 28

* What went wrong:
Error resolving plugin [id: 'dev.flutter.flutter-plugin-loader', version: '1.0.0']
> A problem occurred configuring project ':gradle'.
   > Could not resolve all artifacts for configuration ':gradle:classpath'.
      > Could not download kotlin-compiler-embeddable-1.9.24.jar
         > Could not get resource 'https://plugins.gradle.org/m2/org/jetbrains/kotlin/kotlin-compiler-embeddable/1.9.24/kotlin-compiler-embeddable-1.9.24.jar'.

或者构建过程长时间卡在:

Configuration on demand is an incubating feature.
<-------------> 0% INITIALIZING [26s]
> Evaluating settings

解决方案1: 配置华为云镜像

步骤1: 修改settings.gradle.kts

pluginManagement {
   
    val flutterSdkPath = run {
   
        val properties = java.util.Properties()
        file("local.properties").inputStream().use {
    properties.load(it) }
        val flutterSdkPath = properties.getProperty("flutter.sdk")
        require(flutterSdkPath != null) {
    "flutter.sdk not set in local.properties" }
        flutterSdkPath
    }

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")

    repositories {
   
        // 优先使用华为云镜像
        maven {
   
            url = uri("https://mirrors.huaweicloud.com/repository/maven")
            isAllowInsecureProtocol = true
        }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值