You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

FirebaseAuth.signInWithEmailAndPassword()新版SDK失效问题求助

Firebase Auth signInWithEmailAndPassword() 无回调问题排查与解决

根据你描述的情况:更新Firebase SDK后,输入正确邮箱密码时OnSuccessListenerOnFailureListener都没有触发,错误凭证时能正常触发失败回调,同时日志出现NullPointerException,这大概率是Firebase组件版本不兼容导致的问题,下面是具体的排查和解决步骤:

问题分析

从你的依赖配置可以看到,各个Firebase组件的版本不一致:

  • firebase-auth:15.1.0
  • firebase-core:15.0.2
  • firebase-database:15.0.0
  • ...

Firebase的各个组件内部存在相互调用的逻辑,版本不匹配会导致内部类引用异常,出现你看到的NullPointerException——当输入正确凭证时,Auth模块尝试调用其他Firebase组件的内部方法,但因为版本不兼容拿到了空对象,导致流程崩溃,无法触发任何回调;而错误凭证的校验在Auth模块内部更早阶段完成,所以能正常触发失败回调。

你提供的错误日志:

W/Binder: Binder call failed. com.google.android.gms.internal.firebase_auth.zzv: java.lang.NullPointerException: Attempt to invoke virtual method 'org.json.JSONObject com.google.firebase.auth.internal.zzm.zzbf()' on a null object reference

也验证了这一点:内部类调用时出现了空对象引用,这是版本不兼容的典型表现。

解决方案

1. 统一所有Firebase和Google Play Services依赖版本

将所有Firebase组件和Google Play Services组件的版本统一为同一兼容版本,比如全部使用15.0.2(或者更高的稳定兼容版本)。修改后的依赖示例如下:

dependencies {
    implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:5.5.1'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation:0.12.0'
    implementation 'com.mapbox.mapboxsdk:mapbox-android-navigation-ui:0.12.0'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:27.0.2'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    //noinspection GradleCompatible
    implementation 'com.android.support:support-v4:27.0.2'
    implementation 'com.google.android.gms:play-services-maps:15.0.2'
    //noinspection GradleCompatible
    implementation 'com.android.support:design:27.0.2'
    //noinspection GradleCompatible
    implementation 'com.android.support:support-vector-drawable:27.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    implementation 'com.android.support:cardview-v7:26.1.0'
    implementation 'com.google.android.gms:play-services-location:15.0.2'
    implementation 'com.google.android.gms:play-services-places:15.0.2'
    implementation 'com.google.firebase:firebase-core:15.0.2'
    implementation 'com.google.firebase:firebase-database:15.0.2'
    implementation 'com.google.firebase:firebase-crash:15.0.2'
    implementation 'com.google.firebase:firebase-auth:15.0.2'
    implementation 'com.google.firebase:firebase-messaging:15.0.2'
    implementation 'com.google.firebase:firebase-storage:15.0.2'
    implementation 'com.google.firebase:firebase-functions:15.0.2'
    implementation 'com.simplify:simplify-android:3.0.0'
    implementation 'com.android.volley:volley:1.1.0'
    implementation 'com.google.android.gms:play-services-ads:15.0.2'
    implementation 'com.android.support:multidex:1.0.1'
}

2. 检查Google Services插件版本

确保项目根目录的build.gradle中,Google Services插件的版本与Firebase版本兼容,对应15.x的Firebase版本,插件版本建议使用4.0.1

buildscript {
    dependencies {
        classpath 'com.google.gms:google-services:4.0.1'
    }
}

3. 清理并重建项目

  • 执行Build > Clean Project清除旧的编译缓存
  • 再执行Build > Rebuild Project重新编译项目,避免旧的编译文件残留导致冲突

4. 验证Multidex配置(如果开启了Multidex)

如果你的应用开启了Multidex,确保:

  • app/build.gradleandroid块中添加multidexEnabled true
  • 自定义Application类继承MultiDexApplication,或者在attachBaseContext方法中调用MultiDex.install(this)

补充验证

如果以上步骤解决了问题,那核心原因就是版本不兼容;如果问题依然存在,可以尝试:

  • 检查Firebase控制台中该项目的Auth配置是否正常(比如是否启用了邮箱密码登录方式)
  • 在全新的Demo项目中使用相同版本的Firebase Auth进行测试,排除项目其他代码的干扰

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

火山引擎 最新活动