React Native Android端Google登录失败(DEVELOPER_ERROR)求助
React Native集成Google登录+Firebase时Android端出现DEVELOPER_ERROR问题
在React Native项目中集成@react-native-google-signin/google-signin并结合Firebase实现登录,Android端点击Google登录按钮完成账号输入后,无法跳转至下一页,控制台抛出DEVELOPER_ERROR错误。
错误日志
WARN Possible Unhandled Promise Rejection (id: 0): Error: DEVELOPER_ERROR promiseMethodWrapper@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:2831:45http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:123365:45 generatorResume@[native code] asyncGeneratorStep@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:28377:26 _next@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:28396:29 tryCallOne@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:33548:16http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:33629:27http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:35012:26 _callTimer@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:34891:17 _callReactNativeMicrotasksPass@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:34936:17 callReactNativeMicrotasks@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:35142:44 __callReactNativeMicrotasks@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:3286:46http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:3060:45 __guard@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:3259:15 flushedQueue@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false&app=com.lovedog&modulesOnly=false&runModule=true:3059:21 flushedQueue@[native code] invokeCallbackAndReturnFlushedQueue@[native code]
已尝试的解决方法
- 使用OAuth客户端中的类型3客户端ID
- 重新生成keytool,提取SHA-1、SHA-256并重新上传google-service.json文件
项目相关配置与代码
Android build.gradle配置
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "33.0.0" minSdkVersion = 21 compileSdkVersion = 33 targetSdkVersion = 33 // We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP. ndkVersion = "23.1.7779620" googlePlayServicesAuthVersion = "19.2.0" } repositories { google() mavenCentral() } dependencies { classpath("com.android.tools.build:gradle") classpath("com.facebook.react:react-native-gradle-plugin") classpath 'com.google.gms:google-services:4.3.15' } }
登录页面代码
/* eslint-disable react-native/no-inline-styles */ import React, {useCallback} from 'react'; import {View} from 'react-native'; import {Header} from '../components/Header/Header'; import {useRootNavigation} from '../navigation/RootStackNavigation'; import { GoogleSignin, GoogleSigninButton, } from '@react-native-google-signin/google-signin'; import {useSafeAreaInsets} from 'react-native-safe-area-context'; import auth from '@react-native-firebase/auth'; export const IntroScreen: React.FC = () => { const rootNavigation = useRootNavigation<'Intro'>(); const safeArea = useSafeAreaInsets(); const onPressGoogleSignin = useCallback(async () => { try { const isSignIn = await GoogleSignin.isSignedIn(); if (isSignIn) { await GoogleSignin.signOut(); } const result = await GoogleSignin.signIn({}); const googleCredential = auth.GoogleAuthProvider.credential( result.idToken, ); const authResult = await auth().signInWithCredential(googleCredential); rootNavigation.push('Signup', { screen: 'InputEmail', params: { preInput: { email: result.user.email, name: result.user.name ?? 'Unknown', profileImage: result.user.photo ?? '', }, uid: authResult.user.uid, }, }); } catch (error) { // 여기서 예외를 처리하십시오. console.error('Google Signin Error:', error); // 예외 처리 로직을 추가하세요. } }, [rootNavigation]); return ( <View style={{flex: 1}}> <Header> <Header.Title title="IntroScreen" /> </Header> <View style={{ flex: 1, alignItems: 'center', justifyContent: 'flex-end', paddingBottom: 32 + safeArea.bottom, }}> <GoogleSigninButton onPress={onPressGoogleSignin} /> </View> </View> ); };
进一步排查与解决建议
确认Google Signin初始化配置
检查项目入口(如App.tsx)是否正确初始化GoogleSignin,需使用Android类型的OAuth客户端ID:import { GoogleSignin } from '@react-native-google-signin/google-signin'; GoogleSignin.configure({ clientId: '你的Android OAuth客户端ID', });验证SHA指纹与包名匹配
- 确保Google Cloud控制台中Android客户端ID的包名与
android/app/src/main/AndroidManifest.xml的package属性完全一致(当前项目包名为com.lovedog)。 - 确认使用的SHA指纹是对应构建环境的:
- 调试环境:执行
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android获取指纹。 - 发布环境:使用正式签名文件的指纹,不可混用。
- 调试环境:执行
- 确保Google Cloud控制台中Android客户端ID的包名与
检查google-services.json位置
确保文件放在android/app/目录下,执行cd android && ./gradlew clean清理缓存后重新构建。升级依赖版本
- 将
googlePlayServicesAuthVersion升级至最新稳定版(如20.7.0)。 - 将
com.google.gms:google-services升级至4.4.0及以上版本。
- 将
调试环境额外检查
- 确认模拟器/真机安装的Google Play服务版本足够新。
- 重启模拟器/真机,重新测试登录流程。
内容的提问来源于stack exchange,提问作者heejung Kwon
相关产品推荐
相关产品推荐

