koji-1009 / flutter_auth_ui

A Flutter plugin for using the Firebase Auth UI with Dart in Flutter apps. (not official plugin.)
https://pub.dev/packages/flutter_auth_ui
36 stars 10 forks source link

Sign in with Google & Apple works on simulator but not Android device? #13

Closed fpisidoro closed 3 years ago

fpisidoro commented 4 years ago

Can you please check for me if "Sign in with Google" and "Sign in with Apple" are working on an actual Android device? I am able to get it to work on Android simulator as well as iOS simulator and device, but it fails on an Android device and its difficult to debug without any error log.

Sign in with Email/Password:

Sign in with Apple

Sign in with Google

  firebase_core:  "^0.5.0" 
  cloud_firestore: ^0.14.0+2 
  firebase_auth: ^0.18.0+1 
  flutter_auth_ui: ^0.2.6
import 'package:firebase_auth/firebase_auth.dart';
import 'package:flutter_auth_ui/flutter_auth_ui.dart';

  Widget signInButton() {
    return RaisedButton(
        child: Text(
          'Log In'.i18n,
        ),
        color: Colors.blue,
        textColor: Colors.white,
        onPressed: () async {
          final providers = [
            AuthUiItem.AuthEmail,
            AuthUiItem.AuthApple,
            AuthUiItem.AuthGoogle,
          ];
          const privacyURL =
              'https://www.FreePrivacyPolicy.com/privacy/view/7e2157b394975d571c080e99b0368bce';
          const termsURL =
              'https://www.FreePrivacyPolicy.com/terms/view/f5f738e886618a49196abe8bd0981e89';
          final tosAndPrivacyPolicy = TosAndPrivacyPolicy(termsURL, privacyURL);
          final result =
              await FlutterAuthUi.startUi(providers, tosAndPrivacyPolicy);
          print(result);
        });
  }

If you can confirm that Google and Apple sign in work on a physical Android device, then I assume there is something wrong in my configuration, something that should be different than a simulator configuration. If it fails on an Android device, are you able to get an error log? Thanks

koji-1009 commented 4 years ago

Hi @fpisidoro . Could you check your firebase console? In my env, I can create new firebase user by Google account on Pixel 4a.

Perhaps, your problem is caused by smart-lock https://github.com/firebase/FirebaseUI-Android/blob/master/auth/README.md#smart-lock In my env, I get following error log. Strangely, there is no crash and return true from firebase_auth_ui.

W/SmartLockViewModel(16206): Non-resolvable exception: com.google.android.gms.common.api.ApiException: 16: No eligible accounts can be found.
E/AuthUI  (16206): A sign-in error occurred.
E/AuthUI  (16206): com.firebase.ui.auth.FirebaseUiException: Error when saving credential.
E/AuthUI  (16206):  at com.firebase.ui.auth.viewmodel.smartlock.SmartLockHandler$1.onComplete(SmartLockHandler.java:99)
E/AuthUI  (16206):  at com.google.android.gms.tasks.zzj.run(Unknown Source:4)
E/AuthUI  (16206):  at android.os.Handler.handleCallback(Handler.java:883)
E/AuthUI  (16206):  at android.os.Handler.dispatchMessage(Handler.java:100)
E/AuthUI  (16206):  at android.os.Looper.loop(Looper.java:214)
E/AuthUI  (16206):  at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AuthUI  (16206):  at java.lang.reflect.Method.invoke(Native Method)
E/AuthUI  (16206):  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AuthUI  (16206):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
E/AuthUI  (16206): Caused by: com.google.android.gms.common.api.ApiException: 16: No eligible accounts can be found.
E/AuthUI  (16206):  at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@17.1.0:4)
E/AuthUI  (16206):  at com.google.android.gms.common.internal.zai.zaf(com.google.android.gms:play-services-base@@17.1.0:2)
E/AuthUI  (16206):  at com.google.android.gms.common.internal.zak.onComplete(com.google.android.gms:play-services-base@@17.1.0:6)
E/AuthUI  (16206):  at com.google.android.gms.common.api.internal.BasePendingResult.zaa(com.google.android.gms:play-services-base@@17.1.0:176)
E/AuthUI  (16206):  at com.google.android.gms.common.api.internal.BasePendingResult.setResult(com.google.android.gms:play-services-base@@17.1.0:135)
E/AuthUI  (16206):  at com.google.android.gms.common.api.internal.BaseImplementation$ApiMethodImpl.setResult(com.google.android.gms:play-services-base@@17.1.0:36)
E/AuthUI  (16206):  at com.google.android.gms.internal.auth-api.zzo.zzc(Unknown Source:4)
E/AuthUI  (16206):  at com.google.android.gms.internal.auth-api.zzv.dispatchTransaction(Unknown Source:9)
E/AuthUI  (16206):  at com.google.android.gms.internal.auth-api.zzd.onTransact(Unknown Source:12)
E/AuthUI  (16206):  at android.os.Binder.execTransactInternal(Binder.java:1021)
E/AuthUI  (16206):  at android.os.Binder.execTransact(Binder.java:994)

This error is similar following talks. https://stackoverflow.com/questions/48529851/firebase-auth-ui-no-eligible-accounts-can-be-found-error-on-sign-out


smart-lock does not ask for a password. https://developers.google.com/identity/smartlock-passwords/android

So if you find the new account by Google sign-in, it works fine. However, I'm worried about the error, so check the code in FirebaseAuthUI-android.


To get error log from Android device, logcat is suitable.


Sign in with Apple

Sorry, my Apple Developer Account is expired. I'm not thinking about registering for an account soon, so I can't check the logs.

fpisidoro commented 3 years ago

Yes, this may actually be a smart-lock issue. I'm still doing a few more tests and I'll let you know once I confirm everything is working correctly. Thanks!

fpisidoro commented 3 years ago

So in my attempt to get an error log from an Android device, interestingly it seems everything works fine when the app is installed via USB, and I do get a smart-lock message, but therefore because everything works fine I therefore unable to get an error log. When I reinstall the app via Firebase App Distribution and Codemagic's Testmagic. In other words:

Sign in with Apple

Sign in with Google

I don't understand Smart Lock enough to know why one install method works and another does not.

In reality the only important thing to know is if both Google and Apple logins will work once the app is officially installed from the Google Play Store ---I don't yet know the answer but I'll update once I find out.

I'll keep this issue open for now just in case someone else has the same problem. Thanks!

koji-1009 commented 3 years ago

Hi @fpisidoro, I added enableSmartLockForAndroid option.

https://github.com/koji-1009/flutter_auth_ui/blob/1.0.0/lib/flutter_auth_ui.dart#L109