You need to enable JavaScript to run this app. Flutter使用3.2.4版location插件构建失败,拉取依赖返回403错误
优惠活动
大模型
产品
解决方案
定价
更多

Flutter使用3.2.4版location插件构建失败,拉取依赖返回403错误

问题根因

这不是Google云服务出故障,是两个老配置没更新攒出来的连锁报错:

  • 老版本Flutter项目没适配location 3.x的插件拆分规则,插件拆出来的location_web模块没法被Gradle识别
  • 项目的依赖仓库配置还留着已经彻底停服的Bintray地址,拉Google Play服务的依赖时直接被服务器返回403拦了
解决步骤

1. 修掉location_web找不到的报错

打开android/settings.gradle,把原来的插件解析逻辑替换成下面的配置,补上location_web模块的识别规则:

pluginManagement {
    def flutterSdkPath = {
        def properties = new Properties()
        file("local.properties").withInputStream { properties.load(it) }
        def flutterSdkPath = properties.getProperty("flutter.sdk")
        assert flutterSdkPath != null, "flutter.sdk not set in local.properties"
        return flutterSdkPath
    }()

    includeBuild("$flutterSdkPath/packages/flutter_tools/gradle")
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}

plugins {
    id "com.android.application" version "7.3.0" apply false
}

include ":app"

// 自动识别插件配套的原生模块
def flutterProjectRoot = rootProject.projectDir.parentFile.toPath()
def plugins = new Properties()
def pluginsFile = new File(flutterProjectRoot.toFile(), '.flutter-plugins-dependencies')
if (pluginsFile.exists()) {
    pluginsFile.withInputStream { stream -> plugins.load(stream) }
}
plugins.each { name, path ->
    def pluginDirectory = flutterProjectRoot.resolve(path).resolve('android').toFile()
    if (name == 'location_web') {
        include ':location_web'
        project(':location_web').projectDir = pluginDirectory
    }
}

2. 修掉Bintray 403拉取失败的问题

  • 打开android/build.gradle,在allprojects的仓库配置块里,把所有指向google.bintray.com、jcenter的旧配置全删掉,把Google官方仓库放到解析优先级最前面,配置参考:
allprojects {
    repositories {
        // 删掉所有旧的jcenter、bintray相关配置
        google()
        mavenCentral()
        maven { url "https://storage.googleapis.com/download.flutter.io" }
    }
}
  • 额外处理下location 3.2.4的内置动态依赖问题:这个版本插件内部写的是com.google.android.gms:play-services-location:16.+的动态版本规则,容易顺着旧缓存跑到失效仓库里找版本,直接在android/app/build.gradle的依赖块里锁死固定版本,避免动态解析出问题:
dependencies {
    // 原有依赖不用动
    implementation 'com.google.android.gms:play-services-location:16.0.0'
}
收尾验证
  • 改完所有配置先跑flutter clean清掉本地残留的构建缓存
  • 重新执行构建任务就行
  • 要是还报403,就检查下用户目录下.gradle/init.gradle全局配置里有没有残留的Bintray仓库地址,删干净就好。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.25 15:54:02