4

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!

HondaGuy
  • 1,251
  • 12
  • 29
  • What about version 11.8.0? Also, you're not showing the codepath that invokes SignIn(). It may not matter, but I can't tell how you're getting there. – Doug Stevenson Dec 27 '17 at 04:10
  • Yes, same behaviour on 11.8.0. Sorry, I should have checked that first. I'm on a branch right now that hasn't had its gradle file updated. I'll update my code above with the full implementation so you can see when SignIn gets called. – HondaGuy Dec 27 '17 at 04:20
  • Code updated above. Full implementation is there now. – HondaGuy Dec 27 '17 at 04:24
  • You said the devices have "Play Services v9.2.56". That's really old. The version of Play are supposed be >= the version of the client SDKs. Somehow it is not getting updated on those devices? Do they have enough free space to perform the upgrade? – Doug Stevenson Dec 27 '17 at 04:36
  • Yes, that is really old. I'm testing these versions on the emulator, so no Play Store, and no updates. I have the latest images from the Android SDK manager (both revision 5), but these still just have the really old G.P.S. versions. My app does use the GoogleApiAvailability.isGooglePlayServicesAvailable(Activity activity) function to check the version, but this does not throw an error, nor result in an upgrade prompt in this case. Obviously I can catch the NullPointer, but since the App absolutely needs Firebase Auth, I don't want to back my users into a corner. – HondaGuy Dec 27 '17 at 04:47
  • 2
    Please file a bug report for this. It sounds like the version check isn't working as intended. Also it would be helpful if you know the last known working version of the Firebase library, if there is one. https://firebase.google.com/support/contact/bugs-features/ – Doug Stevenson Dec 27 '17 at 04:54
  • @DougStevenson - Bug filed. Thanks for your help. Happy holidays! (I don't know the last working version. Sorry. May start checking though.) – HondaGuy Dec 27 '17 at 05:07
  • When I run app build with Firebase 11.8.0 on emulator with image version 5 and call `GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable()`, the returned status is SERVICE_VERSION_UPDATE_REQUIRED. Also get logcat message: `W/GooglePlayServicesUtil: Google Play services out of date. Requires 11910000 but found 9256030` – Bob Snyder Dec 27 '17 at 16:54
  • @BobSnyder - Cripes, you're right about that. I had previously tested the play services check, but after introducing a BaseActivity some time ago, the sequencing changed and the signin blows up before the corrective dialog is raised. (Feel free to point and laugh.) I've fixed that problem, but I'm still no closer to a resolution acceptable for users because the older versioned emulators don't have Play Store and so are unable to handle the intent required by the ErrorDialog produced by the GoogleApiAvailability class. – HondaGuy Dec 27 '17 at 22:28
  • Agree that the emulator for API 15/16 does not have Play Store,so you cannot test the entire the entire flow of Play Services update and app restart. But your users with API 15 phones that have Play Services should have the Play Store also. I think you can be pretty confident that the update processing will work. – Bob Snyder Dec 28 '17 at 04:23

1 Answers1

0

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

enter image description here

Amiraslan
  • 794
  • 1
  • 8
  • 19