![](/img/trans.png)
[英]Invariant Violation: requireNativeComponent: "RNSVGSvgViewAndroid" was not found in the UIManager in Android
[英]Invariant Violation: requireNativeComponent: "RNSVGSvgViewAndroid" was not found in the UIManager
我对标题中提到的错误感到头疼。 我正在使用 react-native-gifted-charts ( https://www.npmjs.com/package/react-native-gifted-charts/v/1.0.3 ) 这些图表在 ios 中完美运行,但在 Android 中它一直在崩溃和抛出“不变违规:requireNativeComponent:在 UIManager 中找不到“RNSVGSvgViewAndroid”。” 首先我认为这是我的代码的问题,因为它以前适用于 Android,但即使我反转代码,错误仍然存在。 我正在使用纱线作为包管理器和 Expo 托管工作流。 依赖关系如下。
"react-native": "0.70.5",
"react-native-gifted-charts": "^1.2.42",
"react-native-linear-gradient": "2.6.2",
"react-native-svg": "12.1.0",
■我尝试过的事情
import React, { useState } from "react";
import { View, StyleSheet, Text, TouchableOpacity, ScrollView } from "react-native";
import type { NativeStackScreenProps } from "@react-navigation/native-stack";
import { MainStackParamList } from "../types/navigation";
import dayjs from "dayjs";
import { BarChart, LineChart, PieChart } from "react-native-gifted-charts";
import { useSelector } from "react-redux";
import { RootState } from "../store";
export const StatisticsScreen: React.FC<Props> = () => {
const data=[ {value:50}, {value:80}, {value:90}, {value:70} ]
return (
<BarChart
data={data}
/>
);
};
PS 我也跑了 yarn cache clean 希望它是缓存但没有帮助......
我在尝试使用react-native-heroicons
时也遇到了同样的问题,这需要我安装react-native-svg
但是当我运行npx expo install react-native-svg
时,它起作用了。
安装这个版本。 npx expo 安装 react-native-svg@13.4.0
SVG 渲染需要这个模块
npm install react-native-svg-transformer --save
npx expo install react-native-svg
它对我有用 fontawesome 6 pro 我有 react-native-svg 版本 13.6.0 但是
npx expo install
将其修复为版本 13.4.0
我在使用"react-native-svg": "13.6.0"
时遇到错误,降级为"react-native-svg": "13.4.0"
解决了这个问题。
那么也许您可以尝试升级到13.4.0
版本?
Expo 适用于 13.4.0 版本的react-native-svg
,但react-native-gifted-charts
需要 13.6.0。 所以我安装了react-native-svg
expo install
并覆盖嵌套依赖项以使用 13.4.0 版本也通过添加
"resolutions": {
"react-native-svg": "13.4.0"
}
给我的 package.json。 解决了我的问题
发生这种情况是因为最新的库版本在内部使用
“反应本机 svg”:“13.6.0”
检查这个提交
所以即使我们安装了不同版本的
“反应本机 svg”
它使用目前在 android 中不起作用的版本“13.6.0”。 对我来说降级为
“react-native-gifted-charts”:“1.2.41”
工作了。
Expo 在使用npx expo install [dependency]
时在幕后使用yarn
,这有点尴尬,考虑到他们的初始化脚本(即npx create-expo-app my-app
)使用 npm 安装npm
依赖项。
所以如果你使用
npx expo install react-native-svg
要安装react-native-svg
package,只需确保删除package-lock.json
文件,然后运行
yarn install
所以你的项目中没有多个 package 经理(它可能会对你的依赖项造成破坏)。
我在我的 android 设备上使用 expo。 使用 qr 代码运行应用程序。
我接受了错误->
Invariant Violation: requireNativeComponent: "RNSVGSvgViewAndroid" was not found in the UIManager
因为我是"react-native-svg": "13.6.0",
如果你想解决错误,你需要 downstrain
npx expo install react-native-svg@13.4.0`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.