Javascript 错误代码16“;“已取消”;在本机google登录中

Javascript 错误代码16“;“已取消”;在本机google登录中,javascript,firebase,react-native,google-signin,sha1,Javascript,Firebase,React Native,Google Signin,Sha1,我正在尝试在我的应用程序上实现谷歌登录,一切都运行良好,它要求我在按下登录按钮时选择帐户,但它响应它向我发送代码16“取消”错误 我已通过npm install react native google登录安装了库。 然后我把它链接起来。我在firebase上创建了一个新项目,从那里下载google-services.json并将其粘贴到android/app中。还生成了版本SHA1和外接程序firebase项目 componentDidMount() { GoogleSignin.conf

我正在尝试在我的应用程序上实现谷歌登录,一切都运行良好,它要求我在按下登录按钮时选择帐户,但它响应它向我发送代码16“取消”错误

我已通过npm install react native google登录安装了库。 然后我把它链接起来。我在firebase上创建了一个新项目,从那里下载google-services.json并将其粘贴到android/app中。还生成了版本SHA1和外接程序firebase项目

componentDidMount() {
   GoogleSignin.configure({
     //It is mandatory to call this method before attempting to call signIn()
     scopes: ['https://www.googleapis.com/auth/drive.readonly'],
     // Repleace with your webClientId generated from Firebase console
     webClientId:
       'my client id',
   });
 }
谷歌登录按钮和操作


   <TouchableOpacity 
     onPress={() => _signIn()}
     style={{height:50,width:50,borderRadius:50}}
   >
      <Image
       style={{height:50,width:50}}
        resizeMode='contain'
        source={ImagePath.GOOGLE_ICON}
     />
   </TouchableOpacity>

  _signIn = async () => {
    //Prompts a modal to let the user sign in into your application.
    try {
      await GoogleSignin.hasPlayServices({
        //Check if device has Google Play Services installed.
        //Always resolves to true on iOS.
        showPlayServicesUpdateDialog: true,
      });
      const userInfo = await GoogleSignin.signIn();
      alert(JSON.stringify(userInfo))
      console.log('User Info --> ', userInfo);
      this.setState({ userInfo: userInfo });
    } catch (error) {
      console.log('Message', error.message);
      if (error.code === statusCodes.SIGN_IN_CANCELLED) {
        console.log('User Cancelled the Login Flow');
      } else if (error.code === statusCodes.IN_PROGRESS) {
        console.log('Signing In');
      } else if (error.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
        console.log('Play Services Not Available or Outdated');
      } else {
        alert(JSON.stringify(error))
        console.log('Some Other Error Happened',error);
      }
    }
  };

我期待谷歌成功登录并提供用户数据作为回应。感谢您的任何帮助。谢谢您请共享您的AndroidManifest.xml文件。请检查您是否在清单中添加了任何启动模式。如果是,请删除

  • 解决方法是将
    SHA1
    添加到firebase

  • 如果您正在测试调试版本,则添加
    debug
    SHA1,对于发布版本,请使用
    release
    SHA1

  • 将SHA1证书指纹添加到firebase后

  • 下载firebase
    google services.json文件并将其添加到
    /android/app/

您可以通过下面的命令创建调试密钥

  • cd-android
  • gradlew签名报告


不,我没有添加任何启动模式。
       release {
            if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
                storeFile file(MYAPP_RELEASE_STORE_FILE)
                storePassword MYAPP_RELEASE_STORE_PASSWORD
                keyAlias MYAPP_RELEASE_KEY_ALIAS
                keyPassword MYAPP_RELEASE_KEY_PASSWORD
            }
        }
cd android && ./gradlew signingReport