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