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

Android Studio新版本中Gradle依赖配置失效问题求助

解决项目级Gradle新配置下应用级依赖失效问题

1. 调整项目级Gradle配置

你的项目级配置里,google-services插件的声明可以统一适配新的plugins块写法,无需单独保留buildscript块,调整后如下:

plugins {
  id 'com.android.application' version '7.3.1' apply false
  id 'com.android.library' version '7.3.1' apply false
  id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
  id 'com.google.gms.google-services' version '4.3.14' apply false
}

如果必须保留buildscript块(比如兼容其他老插件),一定要在块内添加Google仓库,否则会拉取不到google-services的classpath:

buildscript {
    repositories {
        google()
        mavenCentral()
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.14'
    }
}

plugins {
  id 'com.android.application' version '7.3.1' apply false
  id 'com.android.library' version '7.3.1' apply false
  id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
}

2. 修正应用级Gradle的插件应用逻辑

在app/build.gradle中,必须正确应用所需插件,且google-services插件要放在最后一行,示例配置如下:

plugins {
    id 'com.android.application'
    id 'org.jetbrains.kotlin.android'
    id 'com.google.gms.google-services'
}

android {
    // 你的Android核心配置(compileSdk、defaultConfig等)
}

dependencies {
    // 此处添加你的业务依赖,比如Firebase相关依赖
    // implementation 'com.google.firebase:firebase-analytics:21.2.0'
}

3. 通用排查步骤

  • 检查settings.gradle是否配置了必要仓库:
    dependencyResolutionManagement {
        repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
        repositories {
            google()
            mavenCentral()
        }
    }
    
  • 同步Gradle前先清理项目:点击Android Studio顶部菜单Build > Clean Project,再执行Sync Project with Gradle Files
  • 验证版本兼容性:确认google-services版本与Android Gradle插件版本匹配,若存在冲突可尝试升级google-services到兼容的最新版本

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.14 11:35:31