不变违规:"RNSVGSvgView" 的本机组件不存在

Invariant Violation: Native component for "RNSVGSvgView" does not exist

经过几天在互联网上的研究,我仍然没有解决我的问题。 我正在使用 react-native-svg 并且遇到了同样的问题: No component found for view with the name "RNSVGPath"

或者这个: Invariant Violation: Native component for "RNSVGSvgView" does not exist

我尝试了很多东西,包括:

react-native unlink react-native-svg
npm uninstall react-native-svg
npm install react-native-svg
react-native link react-native-svg
react-native run-ios

还有:

pod 'RNSVG', :path => '../node_modules/react-native-svg'
rm -rf node_modules
npm install
react-native run-ios

但还是没有... 这是我使用的版本:

"dependencies": {
    "react": "16.1.1",
    "react-native": "0.50.3",
    "react-native-svg": "^6.0.1-rc.1"
}

我尝试直接从 XCode 构建它,但仍然没有...

感谢大家的帮助!

Svg 版本有问题

首先,取消链接 svg,然后删除 svg 的 npm,然后安装新的

"dependencies": {
    "react": "16.1.1",
    "react-native": "0.44.0",
    "react-native-svg": "5.1.8"
}

你应该尝试这样做:

npm install react-native-svg --save //(again)
react-native link react-native-svg //(again)
watchman watch-del-all
rm -rf node_modules/ && yarn cache clean && yarn install

然后在另一个终端

npm start -- --reset-cache

在使用 react-native 运行-ios 启动您的 ios 应用程序之前,您必须手动将 libRNSVG.a 添加到 [=23] 中的链接框架和库=]

然后……多田

我遇到这个问题是因为 "react-native link" 从 RN 0.51 开始就坏了。完全删除后手动链接并重新安装修复了 iOS。

我在 Android 上遇到了同样的问题。

所以,如果您处于相同的条件下,这里有一些东西可以修复它,问题专门发生在 MainApplication 上,所以您想看看:

  • 打开android/app/src/java/com/*/MainApplication.java
  • 在其他导入项之上添加 import com.horcrux.svg.SvgPackage;
  • 在列表 getPackages() 中添加 new SvgPackage()(~第 30 行)

SVG问题,我也塞了4个小时,搞定了

自动 link:

react-native link react-native-svg

不会自动运行,然后您手动运行。

手动 Link:

1 将以下行附加到 android/settings.gradle:

include ':react-native-svg'
project(':react-native-svg').projectDir = new File(rootProject.projectDir,  '../node_modules/react-native-svg/android')

2 在 android/app/build.gradle:

中的依赖项块中插入以下行
implementation project(':react-native-svg')

3 打开`android/app/src/main/java/[...]/MainApplication.java

  • import com.horcrux.svg.SvgPackage; 添加到文件顶部的导入。
  • new SvgPackage() 添加到 getPackages() 方法返回的列表中。如果已有内容,请在上一项前添加一个逗号。