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

Flutter项目无法解析':classpath',找不到google-services插件

解决Flutter安卓项目无法解析com.google.gms:google-services:4.3.13的问题

1. 检查根级build.gradle的仓库配置

确保buildscript块中优先添加Google Maven仓库,这是google-services插件的唯一官方来源:

buildscript {
    repositories {
        google() // 必须放在mavenCentral之前
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.8.1'
        classpath 'com.google.gms:google-services:4.3.13'
    }
}

2. 清理Gradle代理配置

即使开启VPN,Gradle可能仍残留旧代理设置导致请求被Privoxy拦截:

  • 打开全局Gradle配置文件:~/.gradle/gradle.properties(Windows路径:C:\Users\<你的用户名>\.gradle\gradle.properties)
  • 注释或删除所有以http.proxy、https.proxy开头的配置项
  • 同时检查项目内的android/gradle.properties文件,清理相同的代理配置

3. 修复Gradle与安卓插件的版本兼容性

Gradle 7.4与安卓插件3.8.1存在版本不匹配问题,会间接导致依赖解析失败:

  • 方案一:升级安卓插件到适配Gradle7.4的版本,修改根build.gradle:
    classpath 'com.android.tools.build:gradle:7.4.2'
    
    同步修改android/gradle/wrapper/gradle-wrapper.properties中的Gradle版本:
    distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
    
  • 方案二:降低Gradle版本到6.7.1~7.3之间(适配插件3.8.1),修改gradle-wrapper.properties中的distributionUrl对应版本

4. 强制刷新依赖缓存

执行以下命令清理旧缓存并重新拉取依赖:

# macOS/Linux
./gradlew clean build --refresh-dependencies

# Windows
gradlew clean build --refresh-dependencies

也可以手动删除项目根目录下的.gradle/caches文件夹,再重新构建项目

5. 临时关闭Privoxy代理

由于请求被Privoxy返回403,即使使用VPN,代理可能仍在拦截Maven仓库请求,建议暂时关闭Privoxy后再尝试构建

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 18:26:17