Per the Firebase support page, I'm posting here before filing an official bug. Hopefully somebody from the Firebase team can help.
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)
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.
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.
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();
}
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.
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.
Both devices (API 15 & 16) are running Play Services v9.2.56.
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'
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.
I have no issue across a number of physical devices running Android 6 and up.
Thanks!
