You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Firebase安卓端Google登录选账号时触发DEVELOPER_ERROR求助

问题:React Native Google登录选择账号后触发DEVELOPER_ERROR

选择Google账号时触发错误

已花费4天排查仍未解决:在React Native中使用Google登录功能,选择任意账号后,控制台和弹窗均显示DEVELOPER_ERROR。已完成的排查动作:

  • 确认项目与Firebase平台中的SHA-1密钥完全一致
  • 重新下载并使用Google服务json配置文件
  • 确认web client id配置无误,甚至新建了web凭证并使用其ID,但问题依旧。

相关代码

import React, { useState, useEffect } from 'react';
import { View, StyleSheet, Button, Text } from 'react-native'
import {
    GoogleSignin,
    GoogleSigninButton,
    statusCodes,
} from '@react-native-google-signin/google-signin';

const GoogleLogin = ({ navigation }) => {
    const [loggedIn, setloggedIn] = useState(false);
    const [userInfo, setuserInfo] = useState([]);

    useEffect(() => {
        GoogleSignin.configure({
            scopes: ['email'], // 要访问的用户API权限,默认是email和profile
            // androidClientId: '429291652902-u76oe5ffntn1m79h10lv56ecm9bq83n1.apps.googleusercontent.com',
            
            webClientId:
                '429291652902-u1cu4i0n83a9cn4pqrh965kvi21odv82.apps.googleusercontent.com', // 服务端WEB类型的客户端ID,用于验证用户ID和离线访问
            offlineAccess: true, // 是否需要从服务端访问Google API
        });

    }, []);

    const signIn = async () => {
        await GoogleSignin.signOut();
        await GoogleSignin.hasPlayServices();
        await GoogleSignin.signIn()
            .then((response) => {
                console.log("ye aya google ka response", response);
                setisloading(true);
                const body = {
                    email: response?.user?.email,
                    socialId: response?.user?.id,
                    phoneNumber: "",
                    FCMtoken: FCM,
                };
                checkUserExistence(body);
            })
            .catch((err) => {
                console.log(err);
                alert(err.message);
                if (err.code === statusCodes.SIGN_IN_CANCELLED) {
                } else if (err.code === statusCodes.IN_PROGRESS) {

                } else if (err.code === statusCodes.PLAY_SERVICES_NOT_AVAILABLE) {
                } else {
                }
            });
    };

    const signOut = async () => {
        try {
            await GoogleSignin.revokeAccess();
            await GoogleSignin.signOut();
            setloggedIn(false);
            setuserInfo([]);
        } catch (error) {
            console.error(error);
        }
    };

    return (
        <View style={styles.container}>

            <GoogleSigninButton
                style={{ width: 192, height: 48 }}
                size={GoogleSigninButton.Size.Wide}
                color={GoogleSigninButton.Color.Dark}
                onPress={() => signIn()}
            />

            {!loggedIn && <Text>You are currently logged out</Text>}
            {loggedIn && (
                <Button
                    onPress={() => signOut()}
                    title="LogOut"
                    color="red"></Button>
            )}
        </View>
    )
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        alignItems: 'center',
        padding: 10,
        marginTop: 100,
    },

});

export default GoogleLogin;

排查方向及解决方案

1. 配置Android客户端ID

当前代码注释掉了androidClientId,但Android平台登录必须配置对应平台的客户端ID,webClientId仅用于后端验证,客户端登录优先读取Android客户端ID。

  • 前往Google Cloud控制台,找到项目的Android凭证,复制其客户端ID,取消注释并替换到代码中:
androidClientId: '你的Android客户端ID',

2. 补充发布版SHA-1密钥

仅添加调试版SHA-1会导致发布签名的APK验证失败,需同时添加两种环境的SHA-1:

  • 调试版SHA-1获取命令:keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
  • 发布版SHA-1从打包用的签名文件中获取,将两者都添加到Firebase和Google Cloud控制台的对应项目中。

3. 校验Google服务配置文件

  • 确保google-services.json文件放在Android项目的app目录下(路径:android/app/google-services.json)
  • 确认项目级build.gradle已添加Google服务插件依赖:
    dependencies {
        // ...
        classpath 'com.google.gms:google-services:4.3.15'
    }
    
  • 确认模块级app/build.gradle末尾已应用插件:
    apply plugin: 'com.google.gms.google-services'
    

4. 清除缓存并重建应用

  • 卸载设备上的测试应用
  • 清除React Native缓存:
    npx react-native start --reset-cache
    
  • 重新构建安装:
    npx react-native run-android
    

5. 检查OAuth同意屏幕配置

  • 前往Google Cloud控制台的OAuth同意屏幕页面,确认应用已配置测试用户(测试阶段),且已添加email、profile权限
  • 确保登录的Google账号在测试用户列表中

6. 更新Google Sign-In库版本

确保库版本与React Native版本兼容,建议升级到最新稳定版:

npm install @react-native-google-signin/google-signin@latest

内容的提问来源于stack exchange,提问作者Junaid Anwar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 12:30:54