通过 @react-native-google-signin/google-signin 授权时,在 React Native 应用程序中发生崩溃。

4
我在使用@react-native-google-signin/google-signin库时遇到了Google授权的问题。在安卓上,授权正常工作,但在iOS上会崩溃。以下是崩溃日志的片段:
...
AppStoreTools:       14E221
AppVariant:          1:iPhone11,8:16
Beta:                YES
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]

Date/Time:           2023-08-10 13:38:04.8666 +0300
Launch Time:         2023-08-10 13:38:02.2774 +0300
OS Version:          iPhone OS 16.5.1 (20F770750d)
Release Type:        User
Baseband Version:    5.02.02
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Triggered by Thread:  1

...

Thread 1 name:
Thread 1 Crashed:
0   libsystem_kernel.dylib          0x000000020d9b6558 __pthread_kill + 8 (:-1)
1   libsystem_pthread.dylib         0x000000022e7f7118 pthread_kill + 268 (pthread.c:1670)
2   libsystem_c.dylib               0x00000001d5f9b178 abort + 180 (abort.c:118)
3   libc++abi.dylib                 0x000000022e735bf8 abort_message + 132 (:-1)
4   libc++abi.dylib                 0x000000022e725444 demangling_terminate_handler() + 348 (:-1)
5   libobjc.A.dylib                 0x00000001c7b21ea4 _objc_terminate() + 144 (objc-exception.mm:498)
6   libc++abi.dylib                 0x000000022e734fbc std::__terminate(void (*)()) + 16 (:-1)
7   libc++abi.dylib                 0x000000022e734f60 std::terminate() + 56 (:-1)
8   libdispatch.dylib               0x00000001d5f3aec0 _dispatch_client_callout + 40 (object.m:563)
9   libdispatch.dylib               0x00000001d5f42534 _dispatch_lane_serial_drain + 668 (queue.c:3885)
10  libdispatch.dylib               0x00000001d5f430a4 _dispatch_lane_invoke + 384 (queue.c:3976)
11  libdispatch.dylib               0x00000001d5f4dcdc _dispatch_workloop_worker_thread + 648 (queue.c:6507)
12  libsystem_pthread.dylib         0x000000022e7f0ddc _pthread_wqthread + 288 (pthread.c:2618)
13  libsystem_pthread.dylib         0x000000022e7f0b7c start_wqthread + 8 (:-1)

...

Thread 1 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x000000022e739647   x5: 0x000000016b6d2850   x6: 0x000000000000006e   x7: 0x0000000000000300
    x8: 0x1999e4bb343495b2   x9: 0x1999e4ba5f59a5b2  x10: 0x0000000000000200  x11: 0x000000000000000b
   x12: 0x000000000000000b  x13: 0x00000000001ff800  x14: 0x00000000000007fb  x15: 0x0000000095634010
   x16: 0x0000000000000148  x17: 0x000000016b6d3000  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x0000000000001c03  x21: 0x000000016b6d30e0  x22: 0x0000000000000000  x23: 0x000000016b6d30e0
   x24: 0x0000000280841068  x25: 0x0000000000000000  x26: 0x0000000000000114  x27: 0x000000028334d940
   x28: 0x000000028334d940   fp: 0x000000016b6d27c0   lr: 0x000000022e7f7118
    sp: 0x000000016b6d27a0   pc: 0x000000020d9b6558 cpsr: 0x40000000
   esr: 0x56000080  Address size fault

...

我的代码:
import * as React from 'react';
import { View } from 'react-native';
import { useDispatch, useSelector } from 'react-redux';
import { GoogleSignin } from '@react-native-google-signin/google-signin';

export default function Start() {

  const signIn = async () => {
    try {
      await GoogleSignin.hasPlayServices();
      const item: any = await GoogleSignin.signIn();
      console.log('tokens', item);
    } catch (error: any) {
      console.log('error', error);
    }
  };

  const isSignedIn = async () => {
    const isSignedIn1 = await GoogleSignin.isSignedIn();
    if (!!isSignedIn1) {
      getCurrentUserInfo();
    } else {
      console.log('Login Please');
    }
  };

  const getCurrentUserInfo = async () => {
    try {
      const userInfo1 = await GoogleSignin.signInSilently();
      console.log(userInfo1);
    } catch (error: any) {
      console.log('Error', error.message);
    }
  };

  React.useEffect(() => {
    GoogleSignin.configure({
      scopes: [
        'https://www.googleapis.com/auth/youtube',
        'https://www.googleapis.com/auth/youtubepartner',
        'https://www.googleapis.com/auth/userinfo.email',
        'https://www.googleapis.com/auth/userinfo.profile',
      ],
      webClientId:
        '...',
      offlineAccess: true,
      forceCodeForRefreshToken: true,
    });
    isSignedIn();
  }, []);

  return (
      <View>
        <React.Button
          onPress={() => signIn()}
          title="Grant account access"
        />
      </View>
  );
}

发生事故的地方在这几行代码上。
await GoogleSignin.hasPlayServices();
const item: any = await GoogleSignin.signIn();

(在调用signIn函数之前,在控制台显示信息)。
帮助理解iOS上可能出现的问题。如何修复?
我按照IOS安装的所有步骤进行操作https://github.com/react-native-community/react-native-google-signin/blob/master/ios-guide.md 我检查了GoogleSignIn模块是否正确安装在cocoapods中。 重新安装了@react-native-google-signin/google-signin模块 崩溃发生在模拟器和TestFlight中。
我的依赖项:
  "dependencies": {
    "@react-native-google-signin/google-signin": "^10.0.1",
    "@react-navigation/bottom-tabs": "^6.5.8",
    "@react-navigation/native": "^6.1.7",
    "@react-navigation/native-stack": "^6.9.13",
    "@reduxjs/toolkit": "^1.9.5",
    "@types/react-navigation": "^3.4.0",
    "react": "18.2.0",
    "react-dom": "^18.2.0",
    "react-native": "0.72.3",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4",
    "react-redux": "^8.1.1"
  },

1
@NikitasIO 我在反向投票。我认为这个问题更清楚地涉及到与谷歌登录包的关系,并且这个问题有更多的答案和浏览量(我认为这反映了它的可搜索性)。 - undefined
2个回答

8
个人而言,当我调用`GoogleSignin.signIn()`方法时,我的应用程序在上崩溃。
为了解决这个问题,我需要打开Xcode并执行以下操作:
  1. 转到我的`GoogleService-Info.plist`文件
  2. 复制`REVERSED_CLIENT_ID`的值
  3. 导航到项目的TARGETS并选择我的应用程序
  4. 选择`Info`选项卡并导航到`URL Types`部分
  5. 通过点击加号(+)图标向URL Types部分添加一个新项
  6. 将`REVERSED_CLIENT_ID`的值粘贴到URL Schemes字段中。
如果您觉得这些说明不够清晰,您可以观看这个视频,该视频在5:20处详细介绍了这些步骤。

1
这个解决方案对我有效。谢谢。 - undefined
1
这真的起作用了,谢谢。 - undefined

0
降级react-native-google-signin/google-signin到9.0.2版本可以解决这个问题。

安装了9.0.2版本后,崩溃问题仍然存在:... 异常类型:EXC_CRASH (SIGABRT) 异常代码:0x0000000000000000, 0x0000000000000000 终止原因:SIGNAL 6 Abort trap: 6 - undefined
我的React Native版本是0.71.10。 - undefined

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接