KitKat上的Android Firebase Auth崩溃

时间:2018-02-25 14:45:02

标签: android firebase authentication firebase-authentication

我使用Firebase匿名身份验证的应用程序在API19(4.4)上崩溃。

E/AndroidRuntime: FATAL EXCEPTION: main
          Process: com.author.example, PID: 2191
          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.author.example/com.author.example.MainActivity}: java.lang.NullPointerException
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
              at android.app.ActivityThread.access$800(ActivityThread.java:135)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:136)
              at android.app.ActivityThread.main(ActivityThread.java:5017)
              at java.lang.reflect.Method.invokeNative(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:515)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
              at dalvik.system.NativeStart.main(Native Method)
           Caused by: java.lang.NullPointerException
              at com.google.android.gms.internal.zzdvv.zzb(Unknown Source)
              at com.google.android.gms.internal.zzdwc.zza(Unknown Source)
              at com.google.firebase.auth.FirebaseAuth.signInAnonymously(Unknown Source)
              at com.author.example.MainActivity.onCreate(MainActivity.java:64)
              at android.app.Activity.performCreate(Activity.java:5231)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245) 
              at android.app.ActivityThread.access$800(ActivityThread.java:135) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 
              at android.os.Handler.dispatchMessage(Handler.java:102) 
              at android.os.Looper.loop(Looper.java:136) 
              at android.app.ActivityThread.main(ActivityThread.java:5017) 
              at java.lang.reflect.Method.invokeNative(Native Method) 
              at java.lang.reflect.Method.invoke(Method.java:515) 

API 15和16已报告相同的问题,但未找到解决方案。 Firebase Auth crashing on API 15 and 16 with NullPointerException from call to FirebaseAuth.signInAnonymously()

以下是相关的gradle依赖项:

compile 'com.google.firebase:firebase-database:11.8.0'
compile 'com.google.firebase:firebase-auth:11.8.0'
compile 'com.firebaseui:firebase-ui-database:1.0.1'
compile 'com.android.support:appcompat-v7:27.0.2'
compile 'com.android.support:design:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta5'
compile('com.crashlytics.sdk.android:crashlytics:2.7.1@aar') {
    transitive = true
}
compile 'com.google.firebase:firebase-core:11.8.0'
compile 'com.google.firebase:firebase-messaging:11.8.0'
compile 'com.google.maps.android:android-maps-utils:0.5'
compile 'com.google.android.gms:play-services-maps:11.8.0'

任何想法或是我唯一的灵魂来提升最低支持的API?

1 个答案:

答案 0 :(得分:4)

您正在测试的设备或模拟器没有安装与Firebase SDK 11.8.0兼容的Google Play服务版本。在应用程序初始化时,logcat将包含以下消息:

W/GooglePlayServicesUtil: Google Play services out of date

如果真实设备上发生错误,您需要更新设备上的Google Play服务。如果模拟器上发生错误,您需要使用SDK管理器下载最新的模拟器图像,然后选择包含Google API的图像。

由于Firebase需要Google Play服务,因此按照GoogleApiAvailability中的说明,使用the documentation确认其可用是一种良好做法。