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

Firebase实时数据库与认证库版本不兼容问题求助

解决Firebase认证依赖引发的库版本不兼容报错

嘿,终于搞定这个烦人的问题了!跟大家分享下我的经历和解决办法:

问题背景

我想给我的Android应用接入Firebase实时数据库,同时添加手机号和邮箱认证功能。一开始只加实时数据库的build.gradle依赖时一切正常,但一旦加上Firebase认证的依赖,就弹出了版本不兼容的经典报错(就是提示所有com.android.support库必须用同一版本的那个)。

我试过的无效操作

  • 翻遍了Stack Overflow上相关的两个热门问答,照着里面的方法调整后还是没用
  • 把所有相关的Firebase和support库都统一设置成15.0.0版本,同步gradle后报错依旧
  • 还尝试了Firebase官方文档里的另一种依赖配置方式(就是我gradle里注释掉的那段),也没解决问题

最终解决办法

更新Android Studio到最新稳定版本!我把AS更新到当时的最新版后,重新同步gradle,报错直接消失了,功能也正常运行了。推测是旧版本的AS在处理依赖冲突时存在一些bug,更新后就修复了。

我的gradle配置(供参考)

apply plugin: 'com.android.application'
android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "finalproject.mad.com.myapplication"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-iid:15.0.0'
    implementation 'com.google.android.gms:play-services-measurement-base:15.0.0'
    implementation 'com.google.firebase:firebase-database:15.0.0'
    implementation 'com.google.firebase:firebase-auth:15.0.0'
    /*implementation "com.google.firebase:firebase-auth:15.0.0"
    implementation "com.google.android.gms:play-services-auth:15.0.0"
    implementation "com.android.support:design:27.1.1"
    implementation "com.android.support:customtabs:27.1.1"
    implementation "com.android.support:cardview-v7:27.1.1"
    implementation "com.google.firebase:firebase-database:15.0.0"
    implementation "com.android.support:recyclerview-v7:27.1.1"
    implementation "com.android.support:support-v4:27.1.1"*/
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.27 07:12:43