expo-auth-session谷歌登录后出现重复应用选项的问题及解决
问题:谷歌登录后出现重复应用选项,选择右侧导致应用异常
通过expo-auth-session完成谷歌登录操作后,设备弹出选择提示框,显示两个完全相同的应用选项。选择左侧选项时应用可正常运行,选择右侧选项则会导致应用出现异常故障。
提供的配置
app.json
{ "expo": { "owner": "TEST", "name": "TEST", "description": "TESTING APP", "slug": "test-app", "version": "1.0.1", "orientation": "portrait", "icon": "./assets/something-icon.png", "appScheme": "com.test.app", "scheme": "com.test.app", "userInterfaceStyle": "automatic", "currentFullName": "@user/test-app", "originalFullName": "@user/test-app", "splash": { "image": "./assets/images/splash.png", "resizeMode": "contain", "backgroundColor": "#000000" }, "updates": { "fallbackToCacheTimeout": 0, "url": "https://u.expo.dev/code-here" }, "assetBundlePatterns": ["*/"], "ios": { "buildNumber": "1", "supportsTablet": true, "bundleIdentifier": "com.test.app" }, "android": { "icon": "./assets/images/icon.png", "versionCode": 1, "adaptiveIcon": { "foregroundImage": "./assets/icon-foreground.png", "backgroundColor": "#0D0125" }, "package": "com.test.app" }, "web": { "favicon": "./assets/images/favicon.png" }, "plugins": [ [ "expo-image-picker", { "photosPermission": "The app accesses your photos to let you upload into geekzwolf arena" } ] ], "extra": { "eas": { "projectId": "testProjectId" }, "apiArena1": "http://localhost:3000/test", "apiArena": "https://test.app.com/test" }, "runtimeVersion": { "policy": "sdkVersion" } } }
package.json
{ "name": "test-app", "version": "1.0.0", "scripts": { "start": "expo start ", "android": "expo run:android", "ios": "expo run:ios", "web": "expo start --web", "test": "jest --watchAll", "postinstall": "patch-package" }, "jest": { "preset": "jest-expo" }, "dependencies": { "@ethersproject/shims": "^5.7.0", "@expo/vector-icons": "^13.0.0", "@gorhom/bottom-sheet": "^4", "@react-native-clipboard/clipboard": "^1.11.0", "@react-native-community/datetimepicker": "6.2.0", "@react-navigation/bottom-tabs": "^6.0.5", "@react-navigation/material-top-tabs": "^6.2.3", "@react-navigation/native": "^6.0.2", "@react-navigation/native-stack": "^6.1.0", "@react-navigation/stack": "^6.2.3", "@types/react-native-dotenv": "^0.2.0", "axios": "^0.27.2", "axios-auth-refresh": "^3.3.3", "countries-list": "^2.6.1", "date-format": "^4.0.13", "ethers": "^5.7.0", "expo": "~46.0.9", "expo-application": "^4.2.2", "expo-asset": "~8.6.1", "expo-app-auth": "~11.1.0", "expo-auth-session": "~3.7.1", "expo-blur": "~11.2.0", "expo-constants": "~13.2.4", "expo-image-manipulator": "~10.4.0", "expo-image-picker": "~13.3.1", "expo-linear-gradient": "^11.4.0", "expo-linking": "~3.2.2", "expo-random": "~12.3.0", "expo-secure-store": "~11.3.0", "expo-splash-screen": "~0.16.2", "expo-status-bar": "~1.4.0", "expo-system-ui": "~1.3.0", "expo-web-browser": "~11.0.0", "lottie-react-native": "5.1.3", "nativewind": "^2.0.1", "patch-package": "^6.4.7", "prop-types": "^15.8.1", "react": "18.0.0", "react-dom": "18.0.0", "react-native": "0.69.6", "react-native-collapsible": "^1.6.0", "react-native-country-flag": "^1.1.6", "react-native-dotenv": "^3.3.1", "react-native-gesture-handler": "~2.5.0", "react-native-get-random-values": "^1.8.0", "react-native-modal": "^13.0.1", "react-native-pager-view": "5.4.24", "react-native-paper": "^4.12.4", "react-native-raw-bottom-sheet": "^2.2.0", "react-native-reanimated": "~2.9.1", "react-native-reanimated-carousel": "^3.0.4", "react-native-safe-area-context": "4.3.1", "react-native-screens": "~3.15.0", "react-native-simple-accordion": "^1.17.0", "react-native-snap-carousel": "^3.9.1", "react-native-svg": "12.3.0", "react-native-tab-view": "^3.1.1", "react-native-vector-icons": "^9.2.0", "react-native-web": "~0.18.7", "react-native-webview": "11.23.0", "semver": "^7.3.8", "timediff": "^1.1.1", "twrnc": "^3.4.0" }, "devDependencies": { "@babel/core": "^7.12.9", "@ethersproject/shims": "^5.7.0", "@types/react": "~18.0.14", "@types/react-native": "~0.69.1", "@typescript-eslint/eslint-plugin": "^5.33.1", "@typescript-eslint/parser": "^5.33.1", "babel-plugin-module-resolver": "^4.1.0", "eslint": "^8.22.0", "jest": "^26.6.3", "jest-expo": "~44.0.1", "react-test-renderer": "18.0.0", "tailwindcss": "^3.1.8", "typescript": "~4.3.5" }, "private": true, "prettier": { "arrowParens": "always", "bracketSpacing": true, "endOfLine": "lf", "insertPragma": false, "jsxBracketSameLine": false, "printWidth": 80, "proseWrap": "preserve", "tabWidth": 2, "requirePragma": false, "semi": true, "singleQuote": true, "trailingComma": "es5" } }
原因分析
- 重复Scheme配置:
app.json中同时存在appScheme和scheme字段,二者功能重叠,会导致系统注册两个相同的URL Scheme,触发应用选择弹窗。 - 依赖冲突:项目同时安装了已废弃的
expo-app-auth和当前使用的expo-auth-session,两个库会重复注册认证回调的Scheme,导致系统识别出两个应用入口。 - 重复安装/缓存残留:设备上可能存在同一应用的多个版本(比如Expo Go预览版和原生构建版),或者构建缓存未清理,导致系统误判为两个独立应用。
解决方案
1. 清理重复Scheme配置
修改app.json,删除appScheme字段,仅保留scheme:
{ "expo": { // ... 其他配置 "scheme": "com.test.app", // 移除 "appScheme": "com.test.app" // ... 其他配置 } }
2. 移除废弃依赖
卸载expo-app-auth,并替换代码中相关调用为expo-auth-session的API:
npm uninstall expo-app-auth # 或使用yarn yarn remove expo-app-auth
3. 清理设备与缓存
- 卸载设备上所有该应用的版本(包括Expo Go中的预览版)
- 清理项目构建缓存:
expo r -c - 重新构建并安装应用:
# Android expo run:android # iOS expo run:ios
4. 验证标识一致性
确保app.json中的scheme、iOS的bundleIdentifier、Android的package字段完全一致,避免系统因标识不统一产生识别错误。
内容的提问来源于stack exchange,提问作者jted95
相关产品推荐
相关产品推荐

