根据Firebase支持页面,我在发布官方错误之前在此发帖。希望Firebase团队的某些人可以提供帮助。
我的Android应用使用Firebase匿名身份验证。我已经使用模拟器在较旧的Android版本上进行了一些测试,并且在API 15和16上始终获得以下异常(到目前为止......还有更多测试要做):
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 Getting Started指南将Firebase列为支持Android及更高版本的v4.0(API 15),但我想知道这是否有所改变。
我不会在较新版本上出现此错误。我已经检查了API 22及以上,没有遇到任何问题。在我完成17到21的测试之后,我会报告回来。到目前为止,15和16肯定会抛出错误。
我的实施很简单,并与Firebase文档保持一致。
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当然不是null,如上面的调用跟踪所示。例外情况显然来自Firebase代码,由于混淆,我无法确定问题的根源。
也许这是由于模拟设备上的Play服务版本无效?我已经更新了我的图片,并且使用的是Google API图片,但我知道这些图片并不是最新的。
两个设备(API 15和16)都在运行Play Services v9.2.56。
我正在编译到API 27,并编译了Play服务依赖项的v11.6.2:
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。
我在运行Android 6及更高版本的许多物理设备上没有任何问题。
谢谢!
答案 0 :(得分:0)
新的Firebase身份验证版本17.0.0库已将其minSdkVersion更新为API级别16。参考:https://firebase.google.com/support/release-notes/android#version_1700