安装了React Navigation 5后,在启动时使用React Native CLI应用程序崩溃

3
我已安装完所有react-navigation的包,并按照React Navigation的说明进行操作。
安装完成后,当我构建应用程序时,它可以成功构建,但在模拟器上安装后就崩溃了。我也尝试在我的手机上测试,但每次都会崩溃。这是我的项目的屏幕截图:截图
我还发现,只有当我安装了以下内容时,它才会崩溃: #将依赖项安装到裸的React Native项目中
npm install react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view

以下是我项目的其他代码。

package.json

{
  "name": "KhulnaWheels",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "@react-native-community/masked-view": "^0.1.6",
    "@react-navigation/bottom-tabs": "^5.1.0",
    "@react-navigation/drawer": "^5.1.0",
    "@react-navigation/material-bottom-tabs": "^5.1.0",
    "@react-navigation/material-top-tabs": "^5.1.0",
    "@react-navigation/native": "^5.0.8",
    "@react-navigation/stack": "^5.1.0",
    "react": "16.9.0",
    "react-native": "0.61.5",
    "react-native-gesture-handler": "^1.6.0",
    "react-native-paper": "^3.6.0",
    "react-native-reanimated": "^1.7.0",
    "react-native-safe-area-context": "^0.7.3",
    "react-native-screens": "^2.2.0",
    "react-native-tab-view": "^2.13.0"
  },
  "devDependencies": {
    "@babel/core": "^7.6.2",
    "@babel/runtime": "^7.6.2",
    "@react-native-community/eslint-config": "^0.0.5",
    "babel-jest": "^24.9.0",
    "eslint": "^6.5.1",
    "jest": "^24.9.0",
    "metro-react-native-babel-preset": "^0.56.0",
    "react-test-renderer": "16.9.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

android\app\build.gradle (仅包含依赖项部分)


dependencies {
    implementation 'androidx.appcompat:appcompat:1.1.0-rc02'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-alpha03'
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.facebook.react:react-native:+"  // From node_modules


    if (enableHermes) {
        def hermesPath = "../../node_modules/hermes-engine/android/";
        debugImplementation files(hermesPath + "hermes-debug.aar")
        releaseImplementation files(hermesPath + "hermes-release.aar")
    } else {
        implementation jscFlavor
    }
}

index.js

import 'react-native-gesture-handler';
import {AppRegistry} from 'react-native';

import App from './App';
import {name as appName} from './app.json';

AppRegistry.registerComponent(appName, () => App);

在根目录中添加安全区域上下文,请查看此链接 https://www.npmjs.com/package/react-native-safe-area-context - Ashwith Saldanha
检查手势处理程序 Android 设置 https://software-mansion.github.io/react-native-gesture-handler/docs/getting-started.html - Ashwith Saldanha
@AshwithSaldanha 在根节点中添加了安全区域上下文。还要检查手势处理程序。目前还不起作用。和之前一样。 - Jim Khan
打开Android Studio,当应用程序崩溃时,它会在日志记录器中告诉你崩溃的原因。 - Ashwith Saldanha
1个回答

0
请执行下面的命令。
cd android && ./gradlew clean && cd ..

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接