1
votes

My Android Flutter app has Google sign-in using Firebase Authentication. Everything works great in debug mode, but fails in release mode. I have added my SHA-1 fingerprints for both debug and release keystores in the Firebase console, and have updated to the latest google-services.json.

The problem seems to be that I am never getting a FirebaseUser back. This method always returns null:

Future<FirebaseUser> _getCurrentUser() async {
  FirebaseAuth firebaseAuth = FirebaseAuth.instance;
  if (firebaseAuth.currentUser() != null) {
    return await firebaseAuth.currentUser();
  }

  return null;
}

The codelabs example isn't working either. It is returning a GoogleSignInUser, but it's not creating a Firebase user in the console:

Future<GoogleSignInAccount> _ensureLoggedIn() async {
  GoogleSignInAccount user = _googleSignIn.currentUser;
  if (user == null) user = await _googleSignIn.signInSilently();
  if (user == null) {
    user = await _googleSignIn.signIn();
    analytics.logLogin();
  }
  if (_auth.currentUser == null) {
    GoogleSignInAuthentication credentials =
        await _googleSignIn.currentUser.authentication;
    await _auth.signInWithGoogle(
      idToken: credentials.idToken,
      accessToken: credentials.accessToken,
    );
  }

  return user;
}

I have implemented Firebase Authentication before in a native Android app just fine. I have read several other stack overflow posts about this, but I feel like I have tried everything. Any help would be appreciated!

UPDATE:

In a release build, I can read and write to the database if I don't set any read/write rules. I am still unable to create a FirebaseUser. I can create a GoogleSignInAccount, but that doesn't create a Firebase user.

1
have you enabled the google sign in in firebase? - Wahdat Jan
@WahdatKashmiri Yes. Debug builds work fine. It's only release builds that aren't working. - Mark
Do you have an error reporting enabled so you get exception output from the application? - Günter Zöchbauer
@GünterZöchbauer Yes. It is only telling me that my FirebaseUser is null, so I am getting this error when calling user.email: NoSuchMethodError: The getter 'email' was called on null. - Mark

1 Answers

1
votes

I managed to get it working. I just updated all of my dependencies to the latest versions and targeted the latest version of android, then updated my project using this guide and authenticated with Firebase the same way as in this example.

These are my dependencies:

google_sign_in: 2.0.0
firebase_analytics: 0.2.0
firebase_auth: 0.4.0
firebase_database: 0.3.1
firebase_admob: 0.2.2

Hope this helps somebody!