Fixing `GoogleSignIn 0x10461abdc -[GIDSignIn signInWithConfiguration:presentingViewController:hint:additionalScopes:callback:] + 228 (GIDSignIn.m:242)` in Flutter iOS
I recently started using flutterfire_ui's
SignInScreen, and it was working great for Android and Web, but not iOS. For some reason, when I clicked on "Sign in with Google", it would crash the app, and throw this debug info:
Exception Type: EXC_CRASH (SIGABRT) Exception Codes: 0x0000000000000000, 0x0000000000000000 Exception Note: EXC_CORPSE_NOTIFY Triggered by Thread: 0 Last Exception Backtrace: 0 CoreFoundation 0x111f482f8 __exceptionPreprocess + 160 1 libobjc.A.dylib 0x10551131c objc_exception_throw + 56 2 CoreFoundation 0x111f48214 -[NSException initWithCoder:] + 0 3 GoogleSignIn 0x10461bf2c -[GIDSignIn signInWithOptions:] + 364 (GIDSignIn.m:529) 4 GoogleSignIn 0x10461abdc -[GIDSignIn signInWithConfiguration:presentingViewController:hint:additionalScopes:callback:] + 228 (GIDSignIn.m:242) 5 Runner 0x10268a718 -[FLTGoogleSignInPlugin handleMethodCall:result:] + 1776 6 Flutter 0x115401520 __45-[FlutterMethodChannel setMethodCallHandler:]_block_invoke + 112 7 Flutter 0x114e8a328 invocation function for block in flutter::PlatformMessageHandlerIos::HandlePlatformMessage(std::__1::unique_ptr<flutter::PlatformMessage, std::__1::default_delete<flutter::PlatformMessage> >) + 108 8 libdispatch.dylib 0x10bd41fa4 _dispatch_call_block_and_release + 24 9 libdispatch.dylib 0x10bd43768 _dispatch_client_callout + 16 10 libdispatch.dylib 0x10bd53018 _dispatch_main_queue_drain + 1220 11 libdispatch.dylib 0x10bd52b44 _dispatch_main_queue_callback_4CF + 40 12 CoreFoundation 0x111eacb88 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 13 CoreFoundation 0x111ea7318 __CFRunLoopRun + 1956 14 CoreFoundation 0x111ea675c CFRunLoopRunSpecific + 584 15 GraphicsServices 0x113317c98 GSEventRunModal + 160 16 UIKitCore 0x131ee0b74 -[UIApplication _run] + 868 17 UIKitCore 0x131ee4b1c UIApplicationMain + 124 18 Runner 0x102580cd4 main + 64 (AppDelegate.swift:5) 19 dyld_sim 0x102a29fa0 start_sim + 20 20 dyld 0x102aed08c start + 520 21 ??? 0xec63800000000000 ???
I tried looking at the repo's GitHub issues but there was nothing.
However, as it crashed in Debug mode, I noticed that some human-readable error message was briefly displayed. So I used QuickTime and started a screen recording. I clicked "Sign in with Google", and crashed the app. Then I watched the recording again. Here's the error it captured:
Unhandled Exception: PlatformException(google_sign_in, Your app is missing support for the following URL schemes: com.googleusercontent.apps....
It looked familiar, so I searched for that string in my project. I also went into the Firebase Console to check. It turns out I was initializing
SignInScreen with a Google Client ID specific to Web. Instead, I should have passed the platform specific Google Client ID. So I fixed my initialization from:
final String googleClientId = 'some hard coded string'; SignInScreen( auth: auth, providerConfigs: [ GoogleProviderConfiguration( clientId: googleClientId, ) ], ...
final String googleClientId = kIsWeb ? [web specific Google Client ID] : (Platform.isAndroid ? DefaultFirebaseOptions.android.androidClientId : DefaultFirebaseOptions.ios.iosClientId); SignInScreen( auth: auth, providerConfigs: [ GoogleProviderConfiguration( clientId: googleClientId, ) ], ...
And it started working for all platforms. Btw, if the Google Client ID used was the one for Web, why did it even work with Android in the first place? I have no idea.
March 2023 update
I am using flutterfire_cli version 0.2.7, and I have encountered a new bug. In this version, the CLI tool generates the wrong
firebase_option objects: the androidClientId String is in the ios map, not in the android one, so for now I have to use
DefaultFirebaseOptions.ios.androidClientId or it'll throw a null pointer exception.