Expo EAS构建后react-native-qrcode-svg致App崩溃求助
问题描述
在React Native Expo应用中使用react-native-qrcode-svg生成二维码,本地通过Expo Go运行正常,但使用EAS构建并发布到TestFlight测试时,App无报错崩溃。项目依赖配置如下:
{ "scripts": { "dev": "npm run config:localAndDev && expo start --clear", "publish": "npm run config:prod && eas update --branch production --message 'Updating the app'", "build:ios:prod": "npm run config:prod && eas build --platform ios", "build:all:prod": "npm run config:prod && eas build --platform all", "build:android:prod": "npm run config:prod && eas build --platform android", "submit:ios": "eas submit --platform ios", "submit:android": "eas submit --platform android", "android": "react-native run-android", "ios": "react-native run-ios", "web": "expo start --web", "config:localAndDev": "node scripts/set-configuration.js localAndDevelopment", "config:prod": "node scripts/set-configuration.js production", "start": "react-native start", "run:ios:prod": "npm run config:prod && expo run:ios", "run:android:prod": "npm run config:prod && expo run:android" }, "dependencies": { "@expo/vector-icons": "^13.0.0", "@react-native-async-storage/async-storage": "~1.17.3", "@react-navigation/bottom-tabs": "^6.3.2", "@react-navigation/drawer": "^6.4.3", "@react-navigation/native": "^6.0.11", "@react-navigation/stack": "^6.2.2", "@rneui/base": "edge", "@rneui/themed": "edge", "@stripe/stripe-react-native": "0.13.1", "axios": "^0.21.1", "babel-plugin-inline-dotenv": "^1.6.0", "babel-plugin-transform-inline-environment-variables": "^0.4.3", "expo": "^46.0.7", "expo-apple-authentication": "~4.3.0", "expo-asset": "~8.6.1", "expo-auth-session": "^3.7.1", "expo-barcode-scanner": "~11.4.0", "expo-battery": "~6.3.0", "expo-camera": "~12.3.0", "expo-constants": "~13.2.3", "expo-firebase-analytics": "~7.1.1", "expo-google-sign-in": "^11.0.0", "expo-linking": "~3.2.2", "expo-location": "~14.3.0", "expo-notifications": "~0.16.1", "expo-permissions": "~13.2.0", "expo-random": "^12.3.0", "expo-secure-store": "~11.3.0", "expo-splash-screen": "~0.16.1", "expo-status-bar": "~1.4.0", "expo-task-manager": "~10.3.0", "expo-updates": "~0.14.4", "expo-web-browser": "^11.0.0", "firebase": "^9.9.3", "lottie-react-native": "5.1.3", "native-base": "^3.4.12", "react": "18.0.0", "react-dom": "18.0.0", "react-native": "^0.69.4", "react-native-chart-kit": "^6.11.0", "react-native-dotenv": "^3.3.1", "react-native-expo-viewport-units": "^0.0.8", "react-native-gesture-handler": "~2.5.0", "react-native-grid-image-viewer": "^1.2.2", "react-native-modal": "^12.1.0", "react-native-paper": "^4.9.1", "react-native-qrcode-svg": "^6.1.2", "react-native-reanimated": "^2.9.1", "react-native-safe-area-context": "4.3.1", "react-native-screens": "~3.15.0", "react-native-status-bar-height": "^2.6.0", "react-native-svg": "12.3.0", "react-native-vector-icons": "^8.1.0", "react-redux": "^7.2.4", "redux": "^4.1.0", "uuid": "^3.4.0" }, "devDependencies": { "@babel/core": "^7.18.6" }, "private": true, "name": "", "version": "1.0.0" }
解决思路
- 获取崩溃日志定位根因:前往Apple开发者后台的TestFlight模块,找到对应测试版本的崩溃报告,查看具体崩溃栈信息,确认是
react-native-qrcode-svg渲染出错,还是依赖的react-native-svg存在兼容性问题。 - 调整依赖版本适配:
react-native-qrcode-svg@6.1.2与expo 46配套的react-native-svg@12.3.0可能存在适配冲突,尝试降级react-native-qrcode-svg到6.0.0,或升级react-native-svg到expo 46支持的最高兼容版本(如12.3.1)。 - 临时禁用生产代码优化:修改
metro.config.js关闭代码压缩和tree shaking,排查是否是构建优化导致核心逻辑被误删:
重新构建测试,若不再崩溃,再逐步调整优化规则保留必要代码。module.exports = { transformer: { minifyEnabled: false, }, }; - 替换为Expo生态兼容方案:如果上述方法无效,考虑更换为Expo官方生态内的二维码生成工具,比如直接用
expo-svg手动生成,或使用@react-native-community/qrcode(需确认EAS构建兼容性),规避第三方库的适配问题。 - 检查二维码内容合法性:确认生产环境传递给
react-native-qrcode-svg的内容是否过长、存在未转义的特殊字符,尝试传递简单文本测试,排查是否是内容导致的渲染崩溃。
内容的提问来源于stack exchange,提问作者Nate Wessels
相关产品推荐
相关产品推荐

