11

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?

Jose M Vidal
  • 8,816
  • 6
  • 43
  • 48

5 Answers5

19

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:

Patrick Boos
  • 6,789
  • 3
  • 35
  • 36
  • this, I don't know how I didn't realise it till now, but thank you so much, the plist plugin I use with VS Code should've warned me of a duplicate entry ideally but now I will be a bit more careful – king_below_my_lord Nov 04 '18 at 15:37
7

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

Farwa
  • 6,156
  • 8
  • 31
  • 46
1

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

Jose M Vidal
  • 8,816
  • 6
  • 43
  • 48
  • Glad you were able to get it fixed. If you can find a reliable way to reproduce the crash, though, consider filing an issue @ https://github.com/flutter/flutter/issues – RedBrogdon May 29 '18 at 15:57
1

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: "",);
Kirill Karmazin
  • 6,256
  • 2
  • 54
  • 42
  • thanks Bro, this solution is working for me. But every time, it is asking for credentials not showing previous login account.. did you observe this ? – Suresh Vutukuru May 01 '20 at 14:11
0

You have not added the URL scheme as mentioned in the documentation for google_sign_in.

<key>CFBundleURLTypes</key>
<array>
    <dict>
        <key>CFBundleTypeRole</key>
        <string>Editor</string>
        <key>CFBundleURLSchemes</key>
        <array>
            <!-- TODO Replace this value: -->
            <!-- Copied from GoogleService-Info.plist key REVERSED_CLIENT_ID -->
            <string>com.googleusercontent.apps.861823949799-vc35cprkp249096uujjn0vvnmcvjppkn</string>
        </array>
    </dict>
</array>
Anas Lakhani
  • 29
  • 1
  • 4