Expo React Native Google登录Android端无响应问题求助
Expo React Native Google登录Android端无响应问题求助
大家好,我在开发Expo React Native项目时,集成Google登录功能遇到了棘手的问题,折腾了好一阵都没解决,想请各位帮忙排查下。
具体情况:
- 一开始使用最新版相关库,结果全是重定向URL错误的提示;
- 后来把
expo-auth-session降级到^4.0版本,配合Expo Proxy使用后,iOS端的Google登录能正常工作了,但Android端点击登录按钮完全没反应——既不弹出Google的授权页面,也没有任何错误日志输出,就像点击事件没触发一样。
以下是我当前的实现代码:
import * as Google from "expo-auth-session/providers/google"; import { Text, TouchableOpacity } from "react-native"; import { useEffect } from "react"; import * as WebBrowser from "expo-web-browser"; import Svg, { Path } from "react-native-svg"; import useAuth from "~/hooks/auth/useAuth"; WebBrowser.maybeCompleteAuthSession(); const SignWithGoogle = () => { const { handleGoogleSignIn } = useAuth(); const [_, response, promptAsync] = Google.useAuthRequest( { expoClientId: "EXPO_CLIENT_ID(Web)", scopes: ["profile", "email"], androidClientId: "ANDROID_CLIENT_ID(Android)", iosClientId: "IOS_CLIENT_ID(IOS)", }, { projectNameForProxy: "@author/app-name", native: "com.my.schema", } ); useEffect(() => { if (response?.type === "success" && response.authentication?.accessToken) { // API Call to Laravel backend handleGoogleSignIn({ access_token: response.authentication?.accessToken, }); } }, [response]); return ( <TouchableOpacity className="flex-row items-center bg-white rounded-md shadow-md p-3 justify-center gap-x-2" onPress={() => promptAsync({ projectNameForProxy: "@janjacvd/cute-icle" }).catch((e) => console.log(e) ) } > <Svg width={24} height={24} viewBox="0 0 48 48" className="mr-2"> <Path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z" /> <Path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94 c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z" /> <Path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19 C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z" /> <Path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z" /> </Svg> <Text className="text-base text-black text-center"> Continue with Google </Text> </TouchableOpacity> ); }; export default SignWithGoogle;
我已经检查过的点:
- Google Cloud Console里的Android Client ID配置,包名和签名证书指纹都反复核对过,应该是正确的;
- app.json里也配置了对应的schema
com.my.schema; - 点击按钮时,Android端没有进入
promptAsync的catch块,控制台也没有任何错误日志输出。
想问问大家,有没有遇到过类似的Android端无响应的情况?我的代码配置里有没有哪里遗漏或者错误的地方?麻烦各位帮忙看看,谢谢了!
内容来源于stack exchange
相关产品推荐
相关产品推荐

