You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter执行build apk --release失败,遇依赖下载403错误求解决

解决方案

核心问题是Gradle无法从Flutter的Google Storage镜像下载AndroidX依赖(返回403 Forbidden),字体摇树警告不影响构建失败,无需纠结--no-tree-shake-icons参数。以下是针对性解决步骤:

1. 添加国内Maven镜像加速依赖下载

修改项目根目录的build.gradle,在buildscript和allprojects的repositories中添加阿里云镜像,优先从国内源拉取:

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/public' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        google()
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/public' }
        google()
        mavenCentral()
    }
}

2. 强制依赖从官方仓库拉取

如果上述镜像仍无效,可强制Gradle跳过Flutter的镜像源,直接从Google和Maven Central获取AndroidX依赖。在项目根目录的build.gradle中添加resolutionStrategy:

allprojects {
    repositories {
        // 保留原有仓库配置
    }
    configurations.all {
        resolutionStrategy {
            eachDependency { details ->
                if (details.requested.group == 'androidx' || details.requested.group == 'com.google.android.material') {
                    details.useRepository {
                        repository {
                            url 'https://maven.google.com/'
                            name 'Google'
                        }
                    }
                }
            }
        }
    }
}

3. 配置Gradle代理(网络受限环境)

如果处于网络受限环境,在项目根目录的gradle.properties中添加代理配置(替换为可用的代理地址):

systemProp.http.proxyHost=your-proxy-host
systemProp.http.proxyPort=your-proxy-port
systemProp.https.proxyHost=your-proxy-host
systemProp.https.proxyPort=your-proxy-port

4. 清理缓存并重新构建

执行以下命令彻底清理缓存后重新构建:

flutter clean
rm -rf android/.gradle
flutter pub get
flutter build apk --release

内容的提问来源于stack exchange,提问作者Ali

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 19:40:02