[Bug] iOS crashes when Google sign in is not enabled
Description
Summary
Our project is using Firebase Auth to only support logging into our game with Microsoft. However we were seeing a crash on iOS that was fixed by turning on Google Sign In even though we're not using it. Specifically, I needed to include the REVERSED_CLIENT_ID property in the GoogleService-Info.plist, which is only added after enabling Google Sign In.
Detailed description
Tracking down this dependency was a bit obtuse (admittedly I didn't have a Mac handy to actually debug the crash). Since the crash was occurring without any user facing error, I initially assumed there was something wrong with our initialization code. After a few hours with no success, I submitted a crash report from my test device and pulled it from Testflight (didn't learn about this handy feature until today). In the crash report I found the exception originating from Firebase's iOS plugin, specifically getCredentialWithUIDelegate:
Incident Identifier: REDACTED
Hardware Model: iPhone14,5
Process: REDACTED [22464]
Path: /private/var/containers/Bundle/Application/REDACTED
Identifier: REDACTED
Version: 1.0.0 (484)
AppStoreTools: 15E204
AppVariant: 1:iPhone14,5:15
Beta: YES
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: REDACTED [632]
Date/Time: 2024-04-25 14:13:57.9404 -0700
Launch Time: 2024-04-25 14:13:49.0833 -0700
OS Version: iPhone OS 15.7 (19H12)
Release Type: User
Baseband Version: 1.70.01
Report Version: 104
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 47
Last Exception Backtrace:
0 CoreFoundation 0x1d62e1288 __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x1ef015744 objc_exception_throw + 60 (objc-exception.mm:565)
2 CoreFoundation 0x1d6338390 +[NSException raise:format:] + 112 (NSException.m:156)
3 UnityFramework 0x1056160d4 -[FIROAuthProvider getCredentialWithUIDelegate:completion:] + 116 (FIROAuthProvider.m:158)
4 UnityFramework 0x1055f5f78 __52-[FIRAuth signInWithProvider:UIDelegate:completion:]_block_invoke + 124 (FIRAuth.m:655)
5 libdispatch.dylib 0x1d5f46e6c _dispatch_call_block_and_release + 32 (init.c:1517)
6 libdispatch.dylib 0x1d5f48a30 _dispatch_client_callout + 20 (object.m:560)
7 libdispatch.dylib 0x1d5f50124 _dispatch_lane_serial_drain + 668 (inline_internal.h:2622)
8 libdispatch.dylib 0x1d5f50c80 _dispatch_lane_invoke + 392 (queue.c:3944)
9 libdispatch.dylib 0x1d5f5b500 _dispatch_workloop_worker_thread + 648 (queue.c:6732)
10 libsystem_pthread.dylib 0x2474810bc _pthread_wqthread + 288 (pthread.c:2599)
11 libsystem_pthread.dylib 0x247480e5c start_wqthread + 8
Thankfully the source for the plugin is available, so I was able to look up the relevant line which has some extra info:
[NSException raise:NSInternalInconsistencyException
format:@"Please register custom URL scheme '%@' in the app's Info.plist file.",
self->_callbackScheme];
Then it was just a couple of Google searches to figure out that "registering a custom URL" scheme meant REVERSED_CLIENT_ID was missing from my GoogleService-Info.plist.
While I'm still pretty sure requiring Google Sign In is a bug, I think this would have been a lot easier to catch if some validation was added either when the plist is imported, or during a build step. Granted there is this log I saw at build time:
GoogleService-Info.plist file missing REVERSED_CLIENT_ID, Google Sign-In will fail to initialize. However I ignored it since we aren't using Google Sign In 😵
Reproducing the issue
No response
Firebase Unity SDK Version
11.7.0
Unity editor version
2022.3.10
Installation Method
.unitypackage
Problematic Firebase Component(s)
Authentication
Other Firebase Component(s) in use
No response
Additional SDKs you are using
No response
Targeted Platform(s)
Apple Platforms, Android
Unity editor platform
Windows
Scripting Runtime
IL2CPP
Release Distribution Type
Pre-built SDK from https://firebase.google.com/download/unity
Relevant Log Output
No response
If using CocoaPods for Apple platforms, the project's Podfile.lock
Expand Podfile.lock snippet
👀 Replace this line with the contents of your Podfile.lock!
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
So, for an explanation on why this happens. The important part is that any of the OAuthProviders (like the Microsoft one) require adding the custom URL scheme to your XCode project's Info.plist, as documented here: https://firebase.google.com/docs/auth/ios/microsoft-oauth#handle_the_sign-in_flow_with_the_firebase_sdk
The Unity SDK tries to automate that step, by copying it from the REVERSED_CLIENT_ID in your GoogleServices-Info.plist, which is happening here: https://github.com/firebase/firebase-unity-sdk/blob/289f09492a59c7e74f622ca25e8ffede67340178/editor/app/src/XcodeProjectPatcher.cs#L421 That is also where that error about how Google Sign-In will fail to initialize comes up.
Now I'm not sure why the REVERSED_CLIENT_ID seems to only be present in the GoogleServices-Info.plist when Google Sign-In is turned on, I can reach out to folks on my end about that part. I think there is also a CLIENT_ID, that one can derive the reversed version from if needed, so I can see if that is more likely to be present, and if so add some logic for that. At the very least, I can improve that error message, cause it is definitely missing that other things depend on that field as well.