从调用FirebaseAuth.signInAnonymously()到NullPointerException,API 15和16上的Firebase Auth崩溃 [英] Firebase Auth crashing on API 15 and 16 with NullPointerException from call to FirebaseAuth.signInAnonymously()

查看:84
本文介绍了从调用FirebaseAuth.signInAnonymously()到NullPointerException,API 15和16上的Firebase Auth崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Firebase支持页面上,我将在发布正式Bug之前在此处发布.希望Firebase团队的人可以提供帮助.

Per the Firebase support page, I'm posting here before filing an official bug. Hopefully somebody from the Firebase team can help.

我的Android应用使用Firebase匿名身份验证.我一直在使用模拟器在旧版Android上进行一些测试,并始终在API 15和16上收到以下异常(到目前为止...还有更多测试要做):

My Android App uses Firebase anonymous authentication. I've been doing some testing on older Android versions using the emulator and consistently get the following exception on API 15 and 16 (so far...still more testing to do):

Caused by: java.lang.NullPointerException
                  at com.google.android.gms.internal.zzdtp.zzb(Unknown Source)
                  at com.google.android.gms.internal.zzdtw.zza(Unknown Source)
                  at com.google.firebase.auth.FirebaseAuth.signInAnonymously(Unknown Source)

Firebase 入门指南将Firebase列为支持v4.0(API 15 )以及更高版本的Android,但我想知道这是否已更改.

The Firebase Getting Started guide lists Firebase as supporting v4.0 (API 15) of Android and up, but I'm wondering if maybe this has changed.

在较新的版本上,我没有收到此错误.我已经检查了API 22及更高版本,没有任何问题.在完成17到21的测试后,我会报告.到目前为止,15和16肯定会抛出错误.

I do not get this error on newer versions. I've checked API 22 and up and have no trouble. I'll report back after I've finished testing 17 through 21. So far, 15 and 16 definitely throw the error.

我的实现很简单,并且与Firebase文档保持一致.

My implementation is simple, and consistent with the Firebase Docs.

public abstract class BaseActivity extends AppCompatActivity {
private FirebaseAuth mAuth;
private FirebaseUser mUser = null;
private boolean mFirstAuthListenerRun = true;
private FirebaseAuth.AuthStateListener mAuthStateListener = null;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // We want to know if anyone is signed in, so lets listen for that. Per the docs,
    // onCreate is a good place to create the listener:
    // Remember though, the event listener can get fired a lot:
    // https://firebase.google.com/docs/reference/android/com/google/firebase/auth/FirebaseAuth.AuthStateListener
    mAuth = FirebaseAuth.getInstance();
    mAuthStateListener = new FirebaseAuth.AuthStateListener() {
        @Override
        public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
            FirebaseUser user = firebaseAuth.getCurrentUser();
            if (user != null) {
                mFirstAuthListenerRun = false;
                // User is signed in
                Log.d(GetTag(), "onAuthStateChanged:signed_in:" + user.getUid());
                mUser = user;
            } else {
                // User is signed out
                Log.d(GetTag(), "onAuthStateChanged:signed_out");
                mUser = null;
                if(mFirstAuthListenerRun){
                    // We're here because the onAuthStateChanged listener has just been registered, but there wasn't a user yet.
                    // Let's try to sign in.
                    mFirstAuthListenerRun = false;
                    Log.d(GetTag(), "onAuthStateChanged:Attempting SignIn");
                    SignIn();
                }
            }

            AuthStateChanged();
        }
    };
}

@Override
protected void onStart()
{
    super.onStart();
    mAuth.addAuthStateListener(mAuthStateListener);
}

@Override
protected void onStop()
{
    super.onStop();
    mUser = null;
    if (mAuthStateListener != null) {
        mAuth.removeAuthStateListener(mAuthStateListener);
    }
}

public Task<AuthResult> Bounce()
{
    SignOut();
    return SignIn();
}

public Task<AuthResult> SignIn()
{
    return mAuth.signInAnonymously();
}

public void SignOut()
{
    mAuth.signOut();
}


public FirebaseUser GetCurrentUser()
{
    return mUser;
}

public abstract String GetTag();
public abstract void AuthStateChanged();
}

我已经调试,不,mAuth当然也不为空,如上面的调用跟踪中所示.显然,该异常来自Firebase代码内部,由于混淆,我无法确定问题的根源.

I've debugged, and no, mAuth is certainly not null, as shown in the call trace above. The exception is clearly coming from inside the Firebase code, which due to obfuscation, I can't be sure of the source of the problem.

这可能是由于仿真设备上的Play服务版本无效导致的吗?我已经更新了图片,并且正在使用Google API图片,但是我知道这些图片并不总是保持最新.

Perhaps this is due to an invalid Play Service version on the emulated device? I've updated my images, and I am use a Google APIs image, but I know these aren't always kept up to date.

两个设备(API 15和16)都在运行Play服务v9.2.56.

Both devices (API 15 & 16) are running Play Services v9.2.56.

我正在编译API 27,并编译了Play服务依赖项的v11.6.2:

I'm compiling to API 27, and compiling v11.6.2 of the play services dependencies:

implementation 'com.google.android.gms:play-services-maps:11.6.2'
implementation 'com.google.android.gms:play-services-places:11.6.2'
implementation 'com.google.android.gms:play-services-identity:11.6.2'
implementation 'com.google.android.gms:play-services-location:11.6.2'
implementation 'com.android.support:support-v4:27.0.2'
implementation 'com.google.maps.android:android-maps-utils:0.5'
implementation 'com.google.firebase:firebase-core:11.6.2'
implementation 'com.google.firebase:firebase-database:11.6.2'
implementation 'com.google.firebase:firebase-auth:11.6.2'

任何想法都将不胜感激.如果没有Firebase Auth,我的应用程序将完全无用,因此,如果Firebase Auth不再支持较旧的Android版本,则必须启动minSDKTarget.

Any thoughts would be appreciated. My app is completely useless without Firebase Auth, so if Firebase Auth no longer supports the older versions of Android, I'll have to up my minSDKTarget.

我在运行Android 6及更高版本的许多物理设备上都没有问题.

I have no issue across a number of physical devices running Android 6 and up.

谢谢!

推荐答案

新的Firebase身份验证版本17.0.0库已将其minSdkVersion更新为API级别16.参考:

New Firebase Authentication version 17.0.0 library has updated its minSdkVersion to API level 16. Reference: https://firebase.google.com/support/release-notes/android#version_1700

这篇关于从调用FirebaseAuth.signInAnonymously()到NullPointerException,API 15和16上的Firebase Auth崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆