reactjs 不变违背:必需的本机组件:在UI管理器中未找到"RNSVGCircle"

lfapxunr  于 2023-01-01  发布在  React
关注(0)|答案(1)|浏览(129)

我已经安装了yarn add react-native-svg这个库,因为我想设计一个react-native应用程序屏幕上的循环进度条。我得到这个下面的错误,我已经尝试了一切可能的,但它没有得到解决。我还尝试手动链接库(我们不需要这样做,因为我使用react-native〉0.60。它提供自动链接)。错误不变违规:必需的本机组件:在UI管理器中找不到"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"
  }
}
iqxoj9l9

iqxoj9l91#

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故障排除区域

相关问题