Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase_auth Android crash when using the Github AuthProvider #37681

Closed
rafern opened this issue Aug 6, 2019 · 15 comments · Fixed by flutter/engine#11283

Comments

@rafern
Copy link

@rafern rafern commented Aug 6, 2019

When signing in with GithubAuthProvider credentials with Firebase Auth, the app crashes on Android (stack trace below). This happens because info.getProfile() in mapFromAdditionalUserInfo() has JSONObject.NULL values, and JSONObject.NULL is not null, so the message codec does not detect it as a null.

Most likely related to #37294

Stack trace:
E/AndroidRuntime(31676): java.lang.IllegalArgumentException: Unsupported value: null E/AndroidRuntime(31676): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294) E/AndroidRuntime(31676): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291) E/AndroidRuntime(31676): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291) E/AndroidRuntime(31676): at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291) E/AndroidRuntime(31676): at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:57) E/AndroidRuntime(31676): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225) E/AndroidRuntime(31676): at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$SignInCompleteListener.onComplete(FirebaseAuthPlugin.java:691) E/AndroidRuntime(31676): at com.google.android.gms.tasks.zzj.run(Unknown Source) E/AndroidRuntime(31676): at android.os.Handler.handleCallback(Handler.java:836) E/AndroidRuntime(31676): at android.os.Handler.dispatchMessage(Handler.java:103) E/AndroidRuntime(31676): at android.os.Looper.loop(Looper.java:203) E/AndroidRuntime(31676): at android.app.ActivityThread.main(ActivityThread.java:6251) E/AndroidRuntime(31676): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(31676): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1067) E/AndroidRuntime(31676): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:928)

@blasten blasten added the plugin label Aug 6, 2019
@blasten

This comment has been minimized.

Copy link
Contributor

@blasten blasten commented Aug 6, 2019

@mklim

This comment has been minimized.

Copy link
Member

@mklim mklim commented Aug 7, 2019

Thanks for the bug report! /cc @collinjackson and @kroikie, codeowners for firebase_auth.

@Fallenstedt

This comment has been minimized.

Copy link

@Fallenstedt Fallenstedt commented Aug 13, 2019

I have a similar issue when signing in a user with TwitterAuthProvider. The app crashes once I use firebase auth. When I relaunch the app, I am signed in though. This occurs with version 0.14.0+1, 0.14.0+2

import 'package:flutter_twitter_login/flutter_twitter_login.dart';
...
 final TwitterLoginResult twitterResult = await _twitter.authorize();
      final AuthCredential userCredentials = TwitterAuthProvider.getCredential(
          authToken: twitterResult.session.token,
          authTokenSecret: twitterResult.session.secret,
      );

      final AuthResult authResult =
          await _firebaseAuth.signInWithCredential(userCredentials);

This only occurs when I call _firebaseAuth.signinWithCredential. If you would like an example repo, please let me know

W/BiChannelGoogleApi( 1337): [FirebaseAuth: ] getGoogleApiForMethod() returned Gms: com.google.firebase.auth.api.internal.zzak@ca80c74
I/Timeline( 1337): Timeline: Activity_idle id: android.os.BinderProxy@6e838ec time:42979094
D/FirebaseAuth( 1337): Notifying id token listeners about user ( REDACTED ).
D/AndroidRuntime( 1337): Shutting down VM
E/AndroidRuntime( 1337): FATAL EXCEPTION: main
E/AndroidRuntime( 1337): Process: com.example.echo, PID: 1337
E/AndroidRuntime( 1337): java.lang.IllegalArgumentException: Unsupported value: null
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:294)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMessageCodec.writeValue(StandardMessageCodec.java:291)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.StandardMethodCodec.encodeSuccessEnvelope(StandardMethodCodec.java:57)
E/AndroidRuntime( 1337): 	at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225)
E/AndroidRuntime( 1337): 	at io.flutter.plugins.firebaseauth.FirebaseAuthPlugin$SignInCompleteListener.onComplete(FirebaseAuthPlugin.java:691)
E/AndroidRuntime( 1337): 	at com.google.android.gms.tasks.zzj.run(Unknown Source)
E/AndroidRuntime( 1337): 	at android.os.Handler.handleCallback(Handler.java:751)
Launching lib/main.dart on VS501 in debug mode...
Built build/app/outputs/apk/debug/app-debug.apk.
I/FA      ( 1337): App measurement is starting up, version: 16250
I/FA      ( 1337): To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
I/FA      ( 1337): To enable faster debug mode event logging run:
I/FA      ( 1337):   adb shell setprop debug.firebase.analytics.app com.example.echo
E/AndroidRuntime( 1337): 	at android.os.Handler.dispatchMessage(Handler.java:95)
E/AndroidRuntime( 1337): 	at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime( 1337): 	at android.app.ActivityThread.main(ActivityThread.java:6316)
E/AndroidRuntime( 1337): 	at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 1337): 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
E/AndroidRuntime( 1337): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)
Lost connection to device

@Fallenstedt

This comment has been minimized.

Copy link

@Fallenstedt Fallenstedt commented Aug 20, 2019

Have you found a work around? I've been tinkering and digging into the source of the firebase_auth plugin and I cannot create a solution. If you have a found a work around, I would love to know. My android compileSdkVersion and targetSdkVersion are set to 28.

At this point, the firebase_auth might be a Flutter / Firebase adoption blocker until this is fixed.

@rafern

This comment has been minimized.

Copy link
Author

@rafern rafern commented Aug 20, 2019

@Fallenstedt Sorry, I should have added this earlier, but this works for me with the Github auth provider (it might work for Twitter too but I can't test with Twitter):
Comment out line 775 in FirebaseAuthPlugin.java:

  private Map<String, Object> mapFromAdditionalUserInfo(AdditionalUserInfo info) {
    if (info != null) {
      Map<String, Object> additionalUserInfoMap = new HashMap<>();
      //additionalUserInfoMap.put("profile", info.getProfile()); // THIS LINE
      additionalUserInfoMap.put("providerId", info.getProviderId());
      additionalUserInfoMap.put("username", info.getUsername());
      additionalUserInfoMap.put("isNewUser", info.isNewUser());
      return Collections.unmodifiableMap(additionalUserInfoMap);
    } else {
      return null;
    }
  }

Here's a diff:

775c775
<       additionalUserInfoMap.put("profile", info.getProfile());
---
>       //additionalUserInfoMap.put("profile", info.getProfile());

The problem with this is that you won't have additional provider-specific profile info

As for the actual solution, I found that it would be best to just add support for JSONObject.NULL to the message codec, but this would be a fix for the Flutter engine and not firebase_auth:
In StandardMessageCodec.java:

        } else if (value instanceof Map) {
            stream.write(MAP);
            final Map<?, ?> map = (Map) value;
            writeSize(stream, map.size());
            for (final Entry<?, ?> entry: map.entrySet()) {
                writeValue(stream, entry.getKey());
                writeValue(stream, entry.getValue());
            }
        } else if (value.equals(null)) { // These two lines should be added
            stream.write(NULL);
        } else {
            throw new IllegalArgumentException("Unsupported value: " + value);
        }

Again, diff:

292a293,294
>         } else if (value.equals(null)) {
>             stream.write(NULL);
@Fallenstedt

This comment has been minimized.

Copy link

@Fallenstedt Fallenstedt commented Aug 31, 2019

I wanted to post an update to this. I got firebase_auth working on iOS perfectly when authenticating with Twitter. This crash occurs on Android only.

@gasscoelho

This comment has been minimized.

Copy link

@gasscoelho gasscoelho commented Sep 4, 2019

I'm having the same problem. First attempt my app crash but when i launch again it got the authentication. Did you find a solution to run this on Android?

@rafern

This comment has been minimized.

Copy link
Author

@rafern rafern commented Sep 4, 2019

@gasscoelho There is a workaround above in this thread. You can follow the PR for the solution as well in flutter/engine#11283

@gasscoelho

This comment has been minimized.

Copy link

@gasscoelho gasscoelho commented Sep 5, 2019

I'm sorry for this question but i'm new to flutter and git.
I tried to follow your suggestion but I couldn't find this FirebaseAuthPlugin.java file. I tried to look in my project's folder but i was only able to find the .class. Can you send me the path of this file?

@rafern

This comment has been minimized.

Copy link
Author

@rafern rafern commented Sep 5, 2019

@gasscoelho If you're using intellij or androidstudio, on the left there is the project pane. At the bottom of the project pane, open "external libraries". Then, open "flutter plugins". Then, go to the firebase_auth folder and the file should be in android > src.main > java.io.flutter.plugins.firebaseauth > FirebaseAuthPlugin.java. The file extension may be hidden and so the file name may be just FirebaseAuthPlugin
screen

@gasscoelho

This comment has been minimized.

Copy link

@gasscoelho gasscoelho commented Sep 6, 2019

@rafern I was using vscode but then I reopened my project with android studio. I found the file though the path you showed me and changed it as you suggested. I ran my project again and now it's working. Thank you so much!

@dshukertjr

This comment has been minimized.

Copy link

@dshukertjr dshukertjr commented Sep 28, 2019

This issue should not be closed as the issue is not truly resolved.

@rafern

This comment has been minimized.

Copy link
Author

@rafern rafern commented Sep 28, 2019

@dshukertjr I just tried it out and you have to use the dev channel for now, since the fix for the engine hasn't even gone to the beta branch yet. To switch to the dev channel, run this:

flutter channel dev 
flutter upgrade

You will probably run into other issues since its the dev branch, so, if I were you, I would use the workaround mentioned above for now until the fix goes to beta or stable

@yudi43

This comment has been minimized.

Copy link

@yudi43 yudi43 commented Oct 10, 2019

Finally it worked!!!

@kroikie

This comment has been minimized.

Copy link

@kroikie kroikie commented Oct 13, 2019

@rafern

This issue has been moved to FirebaseExtended/flutterfire#348. Any further collaboration will be done there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.