Firebase UI AuthUI.getInstance()抛出NPE

时间:2018-02-06 01:48:28

标签: android firebase firebase-authentication firebaseui

我使用最新的Firebase(11.8.0)和Firebase用户界面(3.2.1)来显示用户身份验证,如下所示:

val providers = Arrays.asList<AuthUI.IdpConfig>(
        AuthUI.IdpConfig.GoogleBuilder().build(),
        AuthUI.IdpConfig.PhoneBuilder().setDefaultCountryIso("id").build(),
        AuthUI.IdpConfig.EmailBuilder().build())

val intent = AuthUI.getInstance().createSignInIntentBuilder()
        .setTheme(R.style.AppTheme)
        .setLogo(R.drawable.ic_logo)
        .setIsSmartLockEnabled(!BuildConfig.DEBUG)
        .setAvailableProviders(providers)
        .build()

startActivityForResult(intent, Constant.RC_SIGN_IN)

此代码有效,但在Android 19上,此代码给出了此错误:

FATAL EXCEPTION: main
Process: com.my.app, PID: 3357
java.lang.NullPointerException
  at com.google.android.gms.internal.zzdvv.zzb(Unknown Source)
  at com.google.android.gms.internal.zzdwc.setFirebaseUIVersion(Unknown Source)
  at com.google.firebase.auth.FirebaseAuth.setFirebaseUIVersion(Unknown Source)
  at com.firebase.ui.auth.AuthUI.<init>(AuthUI.java:208)
  at com.firebase.ui.auth.AuthUI.getInstance(AuthUI.java:244)
  at com.firebase.ui.auth.AuthUI.getInstance(AuthUI.java:232)
  at com.my.app.ui.activity.main.MainActivity$showLoginPrompt$1.onClick(MainActivity.kt:454)
  at android.support.v7.app.AlertController$ButtonHandler.handleMessage(AlertController.java:162)
  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)

我发现来自此AuthUI.getInstance()的错误,我尝试调用类似此val auth = AuthUI.getInstance()的方法,然后出现强制关闭消息。

1 个答案:

答案 0 :(得分:0)

我将回答我自己的问题,事实证明,我使用的模拟器上的原因是过时的Google Play服务版本,当我在使用更新的Google Play服务的真实设备上运行我的应用时,没有发生此类错误。