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

发布于:2025-05-13 ⋅ 阅读:(19) ⋅ 点赞:(0)

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

网站公告

今日签到

点亮在社区的每一天
去签到