我正在尝试使用 Expo 和 Supabase 让 google oauth 正常工作,但仅当尝试在 Android 上登录时,我才不断收到以下错误。我没有使用 Firebase。我在网络或 iOS 上没有收到此错误:
{
"nativeStackAndroid": [],
"userInfo": null,
"message": "DEVELOPER_ERROR",
"code": "10"
}
在一个名为 GoogleSignInButton.native.tsx 的文件中,我有这个
export default function GoogleButton(props: any) {
GoogleSignin.configure({
scopes: [],
webClientId: WEB_CLIENT_ID,
iosClientId: IOS_CLIENT_ID,
offlineAccess: true,
forceCodeForRefreshToken: true,
});
...
}
我相信 Android 登录在几周/几个月前就可以正常工作,但我在开发过程中有一段时间没有测试它,我无法跟踪它出了问题。
同样奇怪的是,当我在 iOS 上登录时,登录显示的应用程序名称与 Android 登录相比不同(如下图)。电影适用于 ios(成功),而 capybaratest 适用于 Android(失败) - 我正在重新使用旧的 google oauth 凭证电影,这是我为之前构建的应用程序创建的。
这是我的 package.json 文件
{
"name": "...",
"main": "expo-router/entry",
"version": "1.0.0",
"scripts": {
"start": "expo start",
"android": "expo run:android",
"ios": "expo run:ios",
"web": "expo start --web",
"test": "jest --watchAll",
},
"jest": {
"preset": "jest-expo"
},
"dependencies": {
"@expo/vector-icons": "^14.0.0",
"@gorhom/bottom-sheet": "^4.6.1",
"@react-native-async-storage/async-storage": "1.21.0",
"@react-native-google-signin/google-signin": "^11.0.1",
"@react-native-picker/picker": "2.6.1",
"@react-navigation/native": "^6.1.17",
"@shopify/restyle": "^2.4.2",
"@supabase/supabase-js": "^2.42.0",
"expo": "~50.0.14",
"expo-font": "~11.10.3",
"expo-linking": "~6.2.2",
"expo-router": "~3.4.8",
"expo-splash-screen": "~0.26.4",
"expo-status-bar": "~1.11.1",
"expo-system-ui": "~2.9.3",
"expo-web-browser": "~12.8.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-native": "0.73.6",
"react-native-dotenv": "^3.4.11",
"react-native-gesture-handler": "~2.14.0",
"react-native-pager-view": "6.2.3",
"react-native-safe-area-context": "4.8.2",
"react-native-screens": "~3.29.0",
"react-native-tab-view": "^3.5.2",
"react-native-url-polyfill": "^2.0.0",
"react-native-web": "~0.19.6"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@types/react": "~18.2.45",
"jest": "^29.2.1",
"jest-expo": "~50.0.4",
"react-test-renderer": "18.2.0",
"typescript": "^5.1.3"
},
"private": true
}
app.json
{
"expo": {
"name": "capybaratest",
"slug": "capybaratest",
"scheme": "com.name.capybaratest",
"version": "1.0.0",
"orientation": "portrait",
"icon": "./assets/images/icon.png",
"userInterfaceStyle": "automatic",
"splash": {
"image": "./assets/images/splash.png",
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.name.capybaratest",
"infoPlist": {
"CFBundleURLTypes": [
{
"CFBundleURLSchemes": [
"com.googleusercontent.apps.141673689420-cstuimdc24iel5o76me2vlint42gj66r"
]
}
]
}
},
"android": {
"adaptiveIcon": {
"foregroundImage": "./assets/images/adaptive-icon.png",
"backgroundColor": "#ffffff"
},
"package": "com.name.capybaratest"
},
"web": {
"bundler": "metro",
"favicon": "./assets/images/favicon.png"
},
"extra": {
"eas": {
"projectId": "6e859fa6-d9e9-4511-b4d8-7f37398500b0"
}
},
"plugins": [
[
"expo-font",
{
"fonts": ["./assets/fonts/OpenSans-Regular.ttf"]
}
]
],
"experiments": {
"tsconfigPaths": true
}
}
}
我尝试创建一个新的博览会安装,使用 Supabase 和其他配置进行试验和错误,并阅读了大量的讨论。我尝试了很多解决方案,但没有任何改变
我最终能够通过此线程的帮助解决此问题:https://github.com/react-native-google-signin/google-signin/issues/1192
问题是由于某种原因,Google 控制台中配置的 SHA-1 证书指纹不正确。我相信控制台会指示用户使用此命令
keytool -keystore path-to-debug-or-production-keystore -list -v
来生成 SHA-1 证书
相反,用户需要做的(在完成所有初始凭据创建之后)是使用本地计算机上的 SHA-1。
摘自我链接的 github 线程:
找出您的开发/生产 apk 的 SHA-1 签名密钥。如果您使用 EAS 进行构建,请通过运行 eas 凭据获取 sha-1,然后选择 android > com.yourbuild.app.dev。将 SHA-1 密钥和相应的包名称放入 Google API 控制台的 Android OAuth 凭证中。
eas credentials
Which build profile do you want to configure?
,我选择了development-simulator
SHA1 Fingerprint
属性