运行Android应用时,在UIManager中找不到RequireNativeComponent:"RNSScreenStackHeaderConfig"

本教程将介绍运行Android应用时,在UIManager中找不到RequireNativeComponent:"RNSScreenStackHeaderConfig"的处理方法,这篇教程是从别的地方看到的,然后加了一些国外程序员的疑问与解答,希望能对你有所帮助,好了,下面开始学习吧。

运行Android应用时,在UIManager中找不到RequireNativeComponent:"RNSScreenStackHeaderConfig" 教程 第1张

问题描述

在Android上运行应用程序时,我收到此错误。它构建正确,但在异常情况下崩溃。我已经安装了REACTION-Native-Screens、@REACTION-Native/导航和https://reactnavigation.org/docs/getting-started/

上列出的依赖项

com.facebook.react.common.JavascriptException:不变冲突:要求本机组件:在UIManager中找不到RNSScreenStackHeaderConfig&Quot;。

This error is located at:
 in RNSScreenStackHeaderConfig
 in Unknown
 in RNSScreen
 in N
 in ForwardRef
 in y
 in E
 in RNSScreenStack
 in w
 in RNCSafeAreaProvider
 in Unknown
 in v
 in Unknown
 in Unknown
 in Unknown
 in ForwardRef
 in Unknown
 in ForwardRef
 in p
 in c
 in P
 in RCTView
 in View
 in RCTView
 in View
 in h, stack:

它在iOS上构建和运行都很好,但当在Android上运行时,它会完全崩溃。我是不是忽略了什么?

这是我的包json。

{
  "name": "<myprojectname>",
  "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 .",
 "postinstall": "npx jetify",
 "android:bundle:debug": "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res/"
  },
  "dependencies": {
 "@react-native-community/async-storage": "^1.8.1",
 "@react-native-community/masked-view": "^0.1.11",
 "@react-navigation/native": "^6.0.2",
 "@react-navigation/native-stack": "^6.1.0",
 "@react-navigation/stack": "^6.0.7",
 "adbkit": "^2.11.1",
 "moment": "^2.24.0",
 "react": "16.9.0",
 "react-native": "0.63.0",
 "react-native-calendar-strip": "^1.4.1",
 "react-native-calendars": "^1.264.0",
 "react-native-firebase": "^5.6.0",
 "react-native-gesture-handler": "^1.10.3",
 "react-native-reanimated": "^2.2.0",
 "react-native-safe-area-context": "^3.3.1",
 "react-native-screens": "3.1.1",
 "react-native-snap-carousel": "^3.8.4",
 "react-native-vector-icons": "^6.6.0",
 "react-navigation": "^4.4.4",
 "react-navigation-stack": "^2.10.4",
 "react-redux": "^7.2.0",
 "redux": "^4.0.5"
  },
  "devDependencies": {
 "@babel/core": "^7.15.0",
 "babel-jest": "24.9.0",
 "eslint": "^6.5.1",
 "jest": "24.9.0",
 "jetifier": "^1.6.5",
 "metro-react-native-babel-preset": "^0.66.2",
 "react-test-renderer": "16.9.0"
  },
  "jest": {
 "preset": "react-native"
  }
}

我真的不知道怎么解决这个问题,我尝试过删除缓存、重新启动Metro、删除节点模块以及所有与&q;相关的&q;错误。甚至在我创建新项目并尝试安装和使用导航库时也会发生此错误。

这是我的入口点,示例复制自反应导航零食。

import * as React from 'react';
import { View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { enableScreens } from 'react-native-screens';

enableScreens(true);
function HomeScreen() {
  return (
 <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Home Screen</Text>
 </View>
  );
}

function DetailsScreen() {
  return (
 <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Text>Details Screen</Text>
 </View>
  );
}

const Stack = createNativeStackNavigator();

function AppTest() {
  return (
 <NavigationContainer>
<Stack.Navigator 
screenOptions={{
  headerStyle: {
 backgroundColor: '#f4511e',
  },
  headerTintColor: '#fff',
  headerTitleStyle: {
 fontWeight: 'bold',
  },
}}
initialRouteName="Home">
  <Stack.Screen  options={{ title: 'My home' }} name="Home" component={HomeScreen} />
  <Stack.Screen  options={{ title: 'My home' }} name="Details" component={DetailsScreen} />
</Stack.Navigator>
 </NavigationContainer>
  );
}

export default AppTest;

有什么建议吗?

推荐答案

我在导航工作期间在iOS上遇到此问题。

我不确定到底是什么解决了这个问题。我重新安装了所有导航包,并运行npx pod-install,清除了Metro缓存、构建数据、派生数据,错误消失了。

好了关于运行Android应用时,在UIManager中找不到RequireNativeComponent:&quot;RNSScreenStackHeaderConfig&quot;的教程就到这里就结束了,希望趣模板源码网找到的这篇技术文章能帮助到大家,更多技术教程可以在站内搜索。