不变违规:"RNSVGSvgView"的原生组件不存在

4 svg ios react-native react-native-ios

经过几天的互联网研究,我还没有解决我的问题.我正在使用react-native-svg并且我遇到了同样的问题: 找不到名为"RNSVGPath"的视图的组件

或者这一个: 不变违规:"RNSVGSvgView"的原生组件不存在

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

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
Run Code Online (Sandbox Code Playgroud)

也:

pod 'RNSVG', :path => '../node_modules/react-native-svg'
rm -rf node_modules
npm install
react-native run-ios
Run Code Online (Sandbox Code Playgroud)

但仍然没有...这是我正在使用的版本:

"dependencies": {
    "react": "16.1.1",
    "react-native": "0.50.3",
    "react-native-svg": "^6.0.1-rc.1"
}
Run Code Online (Sandbox Code Playgroud)

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

谢谢你的帮助!

Tho*_*der 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
Run Code Online (Sandbox Code Playgroud)

然后在另一个终端

npm start -- --reset-cache
Run Code Online (Sandbox Code Playgroud)

在使用react-native run-ios启动ios应用程序之前,必须手动将libRNSVG.a添加到Xcode中的Linked Frameworks和Libraries

然后......田田


Sub*_*tel 5

SVG问题,我也塞了4个小时才得到解决方案。

自动链接:

react-native link react-native-svg
Run Code Online (Sandbox Code Playgroud)

不会自动工作,然后您可以手动工作。

手动链接:

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

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

2 将以下行插入到依赖项块中:android/app/build.gradle:

implementation project(':react-native-svg')
Run Code Online (Sandbox Code Playgroud)

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

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