我的 React Native 项目面临两个问题:
应用程序在首次启动时崩溃:
react-native run-android
时,应用程序会在模拟器/设备上安装并运行,但在首次启动时崩溃。构建 APK 时出错:
Unable to load script. Make sure you're either running Metro (run 'npx react-native start') or that your bundle 'index.android.bundle' is packaged correctly for release.
这是我的
package.json
供参考:
{
"name": "Connect",
"version": "0.0.1",
"private": true,
"scripts": {
"android": "react-native run-android",
"ios": "react-native run-ios",
"lint": "eslint .",
"start": "react-native start",
"test": "jest"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.24.0",
"@react-navigation/bottom-tabs": "^6.6.1",
"@react-navigation/drawer": "^6.7.2",
"@react-navigation/native": "^6.1.18",
"@react-navigation/native-stack": "^6.11.0",
"axios": "^1.7.7",
"react": "18.2.0",
"react-native": "0.74.5",
"react-native-calendars": "^1.1305.0",
"react-native-dotenv": "^3.4.11",
"react-native-gesture-handler": "^2.18.1",
"react-native-linear-gradient": "^2.8.3",
"react-native-reanimated-carousel": "^3.5.1",
"react-native-responsive-dimensions": "^3.1.1",
"react-native-safe-area-context": "^4.11.0",
"react-native-screens": "^3.34.0",
"react-native-svg": "^15.6.0",
"react-native-vector-icons": "^10.2.0"
},
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@babel/runtime": "^7.20.0",
"@react-native/babel-preset": "0.74.87",
"@react-native/eslint-config": "0.74.87",
"@react-native/metro-config": "0.74.87",
"@react-native/typescript-config": "0.74.87",
"@types/react": "^18.2.6",
"@types/react-test-renderer": "^18.0.0",
"babel-jest": "^29.6.3",
"eslint": "^8.19.0",
"jest": "^29.6.3",
"prettier": "2.8.8",
"react-test-renderer": "18.2.0",
"typescript": "5.0.4"
},
"engines": {
"node": ">=18"
}
}
我尝试了以下解决方案,但到目前为止都没有效果:
npx react-native start
。任何解决这些问题的帮助或建议将不胜感激。
react-native-screens
和 react-native-safe-area-context
,以及 npm install
。node_modules
和 package-lock.json
,然后重新安装了依赖项。npm update
并尝试升级和降级软件包版本。npx react-native start --reset-cache
清除了 Metro 缓存。当您使用模拟器时,请查看网络连接情况。如果您未连接到网络,您会看到错误。