Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter google_sign_in crash : __exceptionPreprocess + 294

Tags:

flutter

I am using the google_sign_in plugin in a flutter app to sign in. Using code from the example The code for signing in is just:

GoogleSignIn _googleSignIn = new GoogleSignIn(
  scopes: <String>[
    'email',
    'https://www.googleapis.com/auth/spreadsheets',
    'https://www.googleapis.com/auth/drive.metadata',
  ],
);

Future<Null> _handleSignIn() async {
    print("_handleSignIn");
    try {
      await _googleSignIn.signIn();
    } catch (error) {
      print("We failed");
      print(error);
    }
  }

This works on Android. I press the signin button and there is a popup and I get to signin.

But, this simple example crashes on iOS. When the app calls _handleSignIn above, the _googleSignIn.signIn() call crashes the app (it goes away) with the error message:

flutter: _handleSignIn
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010fe581e6 __exceptionPreprocess + 294
    1   libobjc.A.dylib                     0x000000010f4ed031 objc_exception_throw + 48
    2   CoreFoundation                      0x000000010fecd975 +[NSException raise:format:] + 197
    3   Runner                              0x000000010ce61d8b -[GIDSignIn signInWithOptions:] + 242
    4   Runner                              0x000000010ce5e777 -[GIDSignIn signIn] + 64
    5   Runner                              0x000000010ce591b2 -[FLTGoogleSignInPlugin handleMethodCall:result:] + 2114
    6   Flutter                             0x000000010d1af716 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 118
    7   Flutter                             0x000000010d1c5370 _ZNK5shel<…>
Lost connection to device.

I have no experience building iOS apps so, I probably did something wrong. I followed the instructions and added the GoogleService-Info.plist from firebase.com and updated my Info.plist as instructed.

Any ideas? Any way to get a better error message so I can figure out what might be wrong?

like image 684
Jose M Vidal Avatar asked May 25 '18 20:05

Jose M Vidal


4 Answers

My case was I updated GoogleService-Info.plist but forgot to update CFBundleURLTypes according to REVERSED_CLIENT_ID in Info.plist.

like image 133
Farwa Avatar answered Nov 12 '22 07:11

Farwa


Just had the same problem. It was because I added Google & Facebook login.

Solution:

Adjust Info.plist. Search for CFBundleURLTypes. You will see you have it TWICE. That is wrong. From the Facebook one, copy the <string>fb??????????????</string> part and paste it into the same array in the Google Part. Then remove the CFBundleURLTypes from the Facebook part.

Background:

If you just follow the instructions from Google Login & Facebook login, then you will paste a CFBundleURLTypes section for Google and one for Facebook. Only the latter one will be picked up. So the google one is not in there. So when trying to log in with google sign in, it will raise the exception because it is not correctly setup. Because the google url scheme got overwritten with the facebook one.

Related issues that helped me figure out the problem:

  • App getting crash when click on GoogleSignIn button
  • https://github.com/googlesamples/google-services/issues/81
like image 40
Patrick Boos Avatar answered Nov 12 '22 07:11

Patrick Boos


Not sure what the problem was. I did it all over again and now it works. Maybe it was a cut-n-paste error.

The only new thing I did was set the Team, in the General tab, to my Personal Team. Previously it was unset. No idea if this matters or not.

Set team

like image 1
Jose M Vidal Avatar answered Nov 12 '22 07:11

Jose M Vidal


If you successfully moved GoogleService-Info.plist to the right directory and added CFBundleURLTypes into your Info.plist and still experience crashes then the reason might be in google_sign_in package itself.

There is a known issue with this package on iOS devices (Futter issue)

Long story short: a user named @buuth found that there is a simple lack of null checks for properties hostedDomain and clientId, so you just need to explicitly set them.

GoogleSignIn googleSignIn = GoogleSignIn( 
  scopes: ['email','profile'],
  hostedDomain: "", 
  clientId: "",);
like image 1
Kirill Karmazin Avatar answered Nov 12 '22 07:11

Kirill Karmazin