繁体   English   中英

不变违规:requireNativeComponent:在 UIManager 中找不到“RNSVGCircle”

[英]Invariant Violation: requireNativeComponent: "RNSVGCircle" was not found in the UIManager

我已经安装了yarn add react-native-svg这个库,因为我想在 react-native 应用程序屏幕上设计圆形进度条。 我收到以下错误,我已经尝试了所有可能的方法,但没有得到解决。 我还尝试手动链接库(我们不需要这样做,因为我使用的是 react-native >0.60。它提供自动链接)。 错误不变违规:requireNativeComponent:在 UIManager 中找不到“RNSVGCircle”。

它抛出异常的代码如下

import React from 'react';
import { View, Text } from 'react-native';
import { Circle } from 'react-native-svg';

const CircularProgressBarTest = ({ progress }) => {
  const circumference = 2 * Math.PI * 100;
  const strokeDashoffset = circumference - (progress / 100) * circumference;

  return (
    <View>
      <Circle
        cx={200}
        cy={200}
        r={100}
        stroke="#000"
        strokeWidth={20}
        fill="transparent"
        strokeDasharray={circumference}
        strokeDashoffset={strokeDashoffset}
      />
      <Text>{progress}%</Text>
    </View>
  );
};

export default CircularProgressBarTest;

我的 package.json 文件如下所示

  "dependencies": {
    "@dietime/react-native-date-picker": "^1.2.0",
    "@react-native-async-storage/async-storage": "^1.14.1",
    "@react-native-community/datetimepicker": "^6.5.2",
    "@react-native-community/masked-view": "^0.1.10",
    "@react-native-community/push-notification-ios": "^1.8.0",
    "@react-native-firebase/app": "^12.0.0",
    "@react-native-firebase/auth": "^12.0.0",
    "@react-native-firebase/firestore": "^12.0.0",
    "@react-native-picker/picker": "^1.16.1",
    "@react-navigation/native": "^5.9.4",
    "@react-navigation/stack": "^5.14.4",
    "expo": "~42.0.1",
    "expo-constants": "~11.0.1",
    "expo-font": "^9.1.0",
    "expo-linear-gradient": "^12.0.1",
    "expo-notifications": "^0.12.3",
    "expo-task-manager": "~9.2.2",
    "react": "17.0.1",
    "react-native": "0.64.2",
    "react-native-chart-kit": "^6.12.0",
    "react-native-circular-progress": "*",
    "react-native-circular-progress-indicator": "^4.4.2",
    "react-native-date-picker": "^4.2.5",
    "react-native-elements": "^3.4.2",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-linear-gradient": "^2.6.2",
    "react-native-modalize": "^2.0.8",
    "react-native-paper": "^4.8.1",
    "react-native-radio-check": "^1.0.0",
    "react-native-reanimated": "^2.13.0",
    "react-native-safe-area-context": "^3.2.0",
    "react-native-screens": "~3.4.0",
    "react-native-snap-carousel": "^3.9.1",
    "react-native-splash-screen": "^3.2.0",
    "react-native-svg": "^13.6.0",
    "react-native-unimodules": "~0.14.5",
    "react-native-vector-icons": "^8.1.0",
    "react-usestateref": "^1.0.5"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@babel/runtime": "^7.12.5",
    "@react-native-community/eslint-config": "^2.0.0",
    "babel-jest": "^26.6.3",
    "eslint": "7.14.0",
    "jest": "^26.6.3",
    "metro-react-native-babel-preset": "^0.64.0",
    "react-test-renderer": "17.0.1"
  },
  "jest": {
    "preset": "react-native"
  }
}

Proguard 的问题

当 Proguard 启用时(Android 发布版本默认启用),它会导致运行时错误。 为避免这种情况,请向android/app/proguard-rules.pro添加一个例外:

-keep public class com.horcrux.svg.** {*;}

如果您有构建错误,那么它可能是由缓存问题引起的,请尝试:

watchman watch-del-all
rm -fr $TMPDIR/react-*
react-native start --reset-cache

Or,

rm -rf node_modules
yarn
react-native start --reset-cache

取自react-native-svg故障排除区域

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM