配置Firebase时出现Could not find com.google.gms.google-services错误求助
Flutter Firebase配置构建错误修复
错误信息
The supplied phased action failed with an exception. A problem occurred configuring root project 'android'. Could not resolve all files for configuration ':classpath'. Could not find com.google.gms.google-services:4.3.15:. Required by: project :
问题原因
com.google.gms.google-services:4.3.15版本已不再被官方仓库收录,且与当前使用的Gradle 7.2.0版本存在兼容性问题,导致Gradle无法解析该依赖包。
修复步骤
- 将google-services插件版本升级至与Gradle 7.2.0兼容的稳定版本(如
4.4.0) - 确认
buildscript的仓库配置包含google()和mavenCentral(),确保依赖可正常拉取
修改后的android/build.gradle
buildscript { ext.kotlin_version = '1.7.10' repositories { google() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:7.2.0' // 替换为兼容的google-services版本 classpath "com.google.gms.google-services:4.4.0" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() } } rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') } task clean(type: Delete) { delete rootProject.buildDir }
android/app/build.gradle(保持现有配置即可)
def localProperties = new Properties() def localPropertiesFile = rootProject.file('local.properties') if (localPropertiesFile.exists()) { localPropertiesFile.withReader('UTF-8') { reader -> localProperties.load(reader) } } def flutterRoot = localProperties.getProperty('flutter.sdk') if (flutterRoot == null) { throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.") } def flutterVersionCode = localProperties.getProperty('flutter.versionCode') if (flutterVersionCode == null) { flutterVersionCode = '1' } def flutterVersionName = localProperties.getProperty('flutter.versionName') if (flutterVersionName == null) { flutterVersionName = '1.0' } apply plugin: "com.android.application" apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" android { compileSdkVersion flutter.compileSdkVersion ndkVersion flutter.ndkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } kotlinOptions { jvmTarget = '1.8' } sourceSets { main.java.srcDirs += 'src/main/kotlin' } defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). applicationId "com.example.chatapp" // You can update the following values to match your application needs. // For more information, see: https://docs.flutter.dev/deployment/android#reviewing-the-gradle-build-configuration. minSdkVersion flutter.minSdkVersion targetSdkVersion flutter.targetSdkVersion versionCode flutterVersionCode.toInteger() versionName flutterVersionName } buildTypes { release { // TODO: Add your own signing config for the release build. // Signing with the debug keys for now, so `flutter run --release` works. signingConfig signingConfigs.debug } } } flutter { source '../..' } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation(platform("com.google.firebase:firebase-bom:32.2.2")) implementation("com.google.firebase:firebase-analytics-ktx") } apply plugin: 'com.google.gms.google-services'
额外操作
- 执行
flutter clean清理缓存 - 执行
flutter pub get拉取最新依赖 - 重新运行项目构建
内容的提问来源于stack exchange,提问作者Dheeru Jilagam
相关产品推荐
相关产品推荐

