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

Flutter项目添加firebase-auth至build.gradle引发Kotlin版本冲突

解决Flutter Android端Firebase Auth依赖冲突与Google登录问题

一、先修复Kotlin版本不兼容问题

当前编译失败的核心原因是项目全局Kotlin版本与依赖模块版本不匹配,按以下步骤统一版本:

  1. 修改根目录build.gradle的Kotlin版本
    打开项目根目录的build.gradle文件,更新ext.kotlin_version为1.9.0(与依赖模块的编译版本一致),同时确保Gradle插件版本与你使用的Gradle 8.7匹配:

    buildscript {
        ext.kotlin_version = '1.9.0'
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath "com.android.tools.build:gradle:8.7.0"
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
            classpath 'com.google.gms:google-services:4.4.1'
        }
    }
    
  2. 同步app模块的build.gradle配置
    打开app/build.gradle,确保插件引用和依赖配置正确:

    plugins {
        id 'com.android.application'
        id 'kotlin-android'
        id 'dev.flutter.flutter-gradle-plugin'
        id 'com.google.gms.google-services' // Firebase依赖必须的插件
    }
    
    dependencies {
        implementation platform('com.google.firebase:firebase-bom:32.8.1')
        implementation 'com.google.firebase:firebase-auth'
        implementation 'com.google.firebase:firebase-storage'
        implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    }
    
  3. 清理缓存并重新编译
    执行以下命令彻底清理缓存,避免旧配置干扰:

    flutter clean
    flutter pub get
    cd android
    ./gradlew clean
    ./gradlew build --refresh-dependencies
    cd ..
    flutter run
    

二、解决Google登录“未知错误”问题

编译通过后,排查Google登录的配置问题:

  • 确认Firebase控制台已正确添加Android应用,且google-services.json文件已放置在app模块的根目录下
  • 在Firebase控制台的“Authentication”模块中,启用“Google”登录提供商,并配置正确的OAuth客户端ID
  • 检查AndroidManifest.xml是否添加了网络权限:
    <uses-permission android:name="android.permission.INTERNET" />
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 16:43:36