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

Crash on iOS when clicking the sign in button with Expo #1231

Closed
codejudas opened this issue Dec 29, 2023 · 9 comments
Closed

Crash on iOS when clicking the sign in button with Expo #1231

codejudas opened this issue Dec 29, 2023 · 9 comments

Comments

@codejudas
Copy link

codejudas commented Dec 29, 2023

The app crashes on iOS when clicking the SignIn button, it works on Android.

I've made sure to configure the reverse client id in the url schemes.

I've managed to get the following error from XCode when I reproduce the crash:

Exception '-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x600003718000' was thrown while invoking signIn on target RNGoogleSignin with params (
        {
    },
    480,
    481
)
callstack: (
	0   CoreFoundation                      0x000000011916128d __exceptionPreprocess + 242
	1   libobjc.A.dylib                     0x00000001123b5894 objc_exception_throw + 48
	2   CoreFoundation                      0x00000001191763a3 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
	3   CoreFoundation                      0x0000000119165a20 ___forwarding___ + 1459
	4   CoreFoundation                      0x0000000119167c28 _CF_forwarding_prep_0 + 120
	5   nomad                               0x0000000104d351cd +[GIDSignInCallbackSchemes relevantURLSchemes] + 509
	6   nomad                               0x0000000104d3575d -[GIDSignInCallbackSchemes unsupportedSchemes] + 141
	7   nomad                               0x0000000104d2e145 -[GIDSignIn signInWithOptions:] + 293
	8   nomad                               0x0000000104d2cc0c -[GIDSignIn signInWithConfiguration:presentingViewController:hint:additionalScopes:callback:] + 236
	9   nomad                               0x0000000104e3c807 -[RNGoogleSignin signIn:resolver:rejecter:] + 439
	10  CoreFoundation                      0x0000000119167ebc __invoking___ + 140
	11  CoreFoundation                      0x00000001191651df -[NSInvocation invoke] + 302
	12  CoreFoundation                      0x000000011916544f -[NSInvocation invokeWithTarget:] + 70
	13  nomad                               0x0000000105037c60 -[RCTModuleMethod invokeWithBridge:module:arguments:] + 2528
	14  nomad                               0x000000010503c724 _ZN8facebook5reactL11invokeInnerEP9RCTBridgeP13RCTModuleDatajRKN5folly7dynamicEiN12_GLOBAL__N_117SchedulingContextE + 2036
	15  nomad                               0x000000010503bd75 _ZZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEiENK3$_0clEv + 133
	16  nomad                               0x000000010503bce9 ___ZN8facebook5react15RCTNativeModule6invokeEjON5folly7dynamicEi_block_invoke + 25
	17  libdispatch.dylib                   0x0000000119f13747 _dispatch_call_block_and_release + 12
	18  libdispatch.dylib                   0x0000000119f149f7 _dispatch_client_callout + 8
	19  libdispatch.dylib                   0x0000000119f24856 _dispatch_main_queue_drain + 1362
	20  libdispatch.dylib                   0x0000000119f242f6 _dispatch_main_queue_callback_4CF + 31
	21  CoreFoundation                      0x00000001190bd850 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
	22  CoreFoundation                      0x00000001190b818b __CFRunLoopRun + 2463
	23  CoreFoundation                      0x00000001190b7409 CFRunLoopRunSpecific + 557
	24  GraphicsServices                    0x00000001216ab187 GSEventRunModal + 137
	25  UIKitCore                           0x00000001308673a2 -[UIApplication _run] + 972
	26  UIKitCore                           0x000000013086be10 UIApplicationMain + 123
	27  nomad                               0x0000000104b2f590 main + 96
	28  dyld                                0x00000001110653ee start_sim + 10
	29  ???                                 0x0000000208e543a6 0x0 + 8739177382
)

(nomad is the name of my app btw)

Reproducing the issue

GoogleSignInButton.tsx

export const GoogleButton: React.FC<GoogleButtonProps> = ({ }) => {

  useEffect(() => {
    GoogleSignin.configure({
      scopes: [
        "https://www.googleapis.com/auth/userinfo.profile",
      ],
      webClientId: Platform.OS === 'android' ? <android_client_id> : <web_client_id>,
      iosClientId: Platform.OS === 'ios' ?  <ios_client_id> : undefined,
      offlineAccess: false,
    });
  }, []);

  return (
    <GoogleSigninButton
      size={GoogleSigninButton.Size.Wide}
      color={GoogleSigninButton.Color.Dark}
      onPress={async () => {
        try {
          await GoogleSignin.hasPlayServices();
          const userInfo = await GoogleSignin.signIn();
          console.log('Sign in successful');
        } catch (error: any) {
          /* Error handling to display feedback to user */
        }
      }}
    />
  )
}

App.tsx

export default function App() {
  return (
    <View style={{flex: 1, paddingTop: insets.top, flexDirection: 'column', alignItems: 'center', justifyContent: 'center'}}>
      <GoogleButton  />
    </View>
  );
}

Expected Behavior

Sign in proceeds as expected, console log gets printed.

Actual Behavior

The entire app crashes with a SIGABRT signal for versions > 8.x.x, and the exception above for version == 8.x.x.

Environment

I've tried the following versions of @react-native-google-signin/google-signin:

  • 11.0.0 - Fails with a pod install error (CocoaPods could not find compatible versions for pod "ExpoAdapterGoogleSignIn")
  • 10.1.1 - Crashes with no error message in the emulator (aka goes to home screen, no feedback), if running via xcode then provides the error above.
  • 9.1.0 - Crashes with no erorr message in the emulator, if running via xcode then provides the error above.
  • 8.2.2 - Crashes with error message above and shows it in the emulator.

Emulator iOS version is iOS 17.0, i'm running it on an M2 Mac if that matters.
React Native version is 0.72.6
Expo version is 49.0.15

Podfile is auto-generated by expo, but I've configured it to add this line based on various stack overflow/github issues trying to debug the crash:

platform :ios, podfile_properties['ios.deploymentTarget'] || '13.0'
@htcdang
Copy link

htcdang commented Dec 31, 2023

I observed the same behaviour in my expo app and solved it by providing the iosUrlScheme option to the config plugin. You can read more here.

@codejudas
Copy link
Author

@htcdang I already have this in my app.json for a few days now of trying to get this working:

"plugins": [
       ....,
        "@react-native-google-signin/google-signin",
        {
          "iosUrlScheme": "com.googleusercontent.apps.xxxxxxxxx"
        }
      ],

@vonovak
Copy link
Member

vonovak commented Dec 31, 2023

Hello and thanks for reporting,
judging by the stack trace (mentions of unsupportedSchemes and relevantURLSchemes) I'm guessing that the error has to to do with checking the url schemes the app supports.

I was unable to reproduce this on my test project so without a runnable reproduction, I won't be able to assist further.

As for the config plugin iosUrlScheme parameter, please note that this parameter is only available to sponsors of the module, it's not part of the public package.

Finally, in the provided snippet

GoogleSignin.configure({
      scopes: [
        "https://www.googleapis.com/auth/userinfo.profile",
      ],
      webClientId: Platform.OS === 'android' ? <android_client_id> : <web_client_id>,
      iosClientId: Platform.OS === 'ios' ?  <ios_client_id> : undefined,
      offlineAccess: false,
    });

the webClientId parameter is wrong: it should always be the web client id, not the android_client_id.

I'm going to close this but feel free to provide a runnable repro so I can debug this.
Thank you 🙂

@vonovak vonovak closed this as completed Dec 31, 2023
@codejudas codejudas changed the title Crash on iOS when clicking the sign in button Crash on iOS when clicking the sign in button with Expo Jan 4, 2024
@codejudas
Copy link
Author

@vonovak Your analysis of the stack trace helped me find the issue! I opened the project in Xcode and in the Info > Url Schemes section there was an empty url scheme for some reason, removing that fixed the crash.

With some trial and error I found that this section I had added to my app.json was causing the empty url schemes:

{
  "expo": {
    "ios": {
      ...,
      "infoPlist": {
        "CFBundleURLTypes": [
        {
           "CFBundleURLSchemes": "com.googleusercontent.apps.xxxxxxxxxxxxx"
         }
        ]
      }
    }
  }
}

Per [this documentation|https://docs.expo.dev/versions/latest/config/app/#infoplist] on the expo website, but probably I did something wrong. I think I had added this because I had googled some stuff about needing the url bundles in the info.plist and thought that would do it.. evidently not.

Anyways just putting this here in case some other unfortunate soul happens to stumble into the same set of circumstances. Thanks for your help!

@mohdabbas
Copy link

mohdabbas commented Feb 12, 2024

I am still facing the same issue! The app is getting crashed on iOS. On Android it is working fine. My app is managed by expo so I cannot use xcode. I am not using the sponsored version.

app.json

"plugins": [
"expo-apple-authentication",
[
"@react-native-google-signin/google-signin",
{
"iosUrlScheme": "com.googleusercontent.apps.xxx-xxx"
}
]
],
"ios:{
"bundleIdentifier": "myapp",
"infoPList": {
"CFBundleURLTypes": [{"CFBundleURLSchemes":["com.googleusercontent.apps.xxx-xxx"]}],
"UIRequiresFullScreen": true,
.....

GoogleLogin.js

const SignIn = async () => {
try {
GoogleSignin.configure({
webClientId: "xxx-xxx.apps.googleusercontent.com",
androidClientId: "xxx-xxx.googleusercontent.com",
iosClientId: "xxx-xxx.apps.googleusercontent.com",
})
// GoogleSignin.configure({
// scopes: [
// "https://www.googleapis.com/auth/userinfo.profile",
// ],
// webClientId: Platform.OS === 'android' ? 'xxx-xxx.apps.googleusercontent.com' : 'xxx-xxx.apps.googleusercontent.com',
// iosClientId: Platform.OS === 'ios' ? 'xxx-xxx.apps.googleusercontent.com' : undefined,
// offlineAccess: false,
// });
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();

I am unable to get any userInfo, instead the app crashes. Unable to get any logs!

I am using:

"expo": "~49.0.6",
"react-native": "0.72.6",
"@react-native-google-signin/google-signin": "^11.0.0"

Thanks in advance for any suggestion/help.

@erickreutz
Copy link

The problem is that the config plugin only works when using GoogleService-Info.plist. I've looked through the code and the config plugin uses expo/config-plugins IOSConfig.Google.withGoogle internally which does nothing with iosUrlScheme and so when you run expo prebuild it fails to add the scheme to the ios apps Info.plist.

That's why configuring it directly works. Which is what the expo docs suggest. i.e. You could also add it to ExpoConfig['scheme'] because it can be an array

{
  "ios": {
    ...
    "infoPlist": {
      "CFBundleURLTypes": [
        {
          "CFBundleURLSchemes": ["com.googleusercontent.apps.17898xxxxxx-xxxxxqhqj0exxxxxpl03xxx"]
        }
      ]
    }
  }
}

I'm further confused with this library because the docs reference versions 12 and 13 that do not exist in npm

image

@rajatpaymint
Copy link

rajatpaymint commented Mar 11, 2024

Is anyone able to solve this yet? I have followed the above steps and still have the same issue of app crashing on clicking 'Google Signin'. The crash occurs when executing Googlesignin.Singin(). Using iOS dev build.
I am using an expo-managed workflow.
This is my app.json
"googleServicesFile": "./GoogleService-Info.plist", "infoPlist": { "CFBundleURLTypes": [ { "CFBundleURLSchemes": ["com.googleusercontent.apps.-----"] } ],
Also tried this:
"plugins": [ [ "@react-native-google-signin/google-signin", { "iosUrlScheme": "com.googleusercontent.apps.--------" } ],
Have also tried adding directly to plist file:
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>com.googleusercontent.apps.-------</string> </array> </dict> </array>

@roy-law
Copy link

roy-law commented May 8, 2024

I don't know what got it working but I finally did manage to get it working on iOS. I am using Expo managed workflow and I do run it with EAS build to do prebuild step.

@uoon-dev
Copy link

@erickreutz Thank you very much. It works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants