React Native Expo嵌入Unity报错:ViewManagerResolver返回RNUnity/RCTRNUnityView空值
React Native Expo嵌入Unity时ViewManagerResolver返回null的问题
配置详情
- React Native Expo版本:通过
npx create-expo-app@latest创建 - Unity版本:2022.3.42f1
- React Native Unity包版本:最新版(同时尝试过教程推荐的1.0.7版本)
- Unity构建路径:导出至React Native项目根目录下的
unity/builds/android
执行步骤
- 将Unity项目导出至
unity/builds/android路径 - 创建
UnityScreen.tsx文件,代码如下:
import React, { useRef } from 'react'; import UnityView from '@azesmway/react-native-unity'; import { View } from 'react-native'; const Unity = () => { const unityRef = useRef<UnityView>(null); return ( <View style={{ flex: 1 }}> <UnityView ref={unityRef} style={{ flex: 1 }} /> </View> ); }; export default Unity;
- 将该页面添加至导航栈
- 使用
npx expo start启动应用
问题现象
应用初始运行正常,但点击按钮导航至Unity页面时,出现错误:
ViewManagerResolver returns null for either RNUnity or RCTRNUnityView
已尝试方案
- 严格遵循react-native-unity的GitHub README配置步骤
- 按照Medium教程完成操作
- 切换至教程推荐的1.0.7版本react-native-unity
内容的提问来源于stack exchange,提问作者Omar Yehia
相关产品推荐
相关产品推荐

