RNCardView的本机组件不存在

时间:2018-02-18 15:45:41

标签: react-native cardview

我知道有很多类似的帖子都有这个错误,但是没有一个能解决我的问题..

我一直在尝试在我的项目上设置react-native-cardview,但我一直收到以下错误:

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

This error is located at:
    in RCTText (at Text.js:548)
    in Text (at Button.js:137)
    in RCTView (at View.js:71)
    in View (at Button.js:136)
    in TouchableNativeFeedback (at Button.js:128)
    in Button (at FormLogin.js:45)
    in RNCardView (at FormLogin.js:21)
    in RCTView (at View.js:71)
    in View (at FormLogin.js:20)
    in FormLogin (at SceneView.js:17)
    in SceneView (at CardStack.js:374)
    in RCTView (at View.js:71)
    in View (at CardStack.js:373)
    in RCTView (at View.js:71)
    in View (at CardStack.js:372)
    in RCTView (at View.js:71)
    in View (at createAnimatedComponent.js:147)
    in AnimatedComponent (at Card.js:12)
    in Card (at PointerEventsContainer.js:39)
    in Container (at CardStack.js:414)
    in RCTView (at View.js:71)
    in View (at CardStack.js:348)
    in RCTView (at View.js:71)
    in View (at CardStack.js:347)
    in CardStack (at CardStackTransitioner.js:66)
    in RCTView (at View.js:71)
    in View (at Transitioner.js:142)
    in Transitioner (at CardStackTransitioner.js:19)
    in CardStackTransitioner (at StackNavigator.js:38)
    in Unknown (at createNavigator.js:13)
    in Navigator (at createNavigationContainer.js:214)
    in NavigationContainer (at registerRootComponent.js:35)
    in RootErrorBoundary (at registerRootComponent.js:34)
    in ExpoRootComponent (at renderApplication.js:35)
    in RCTView (at View.js:71)
    in View (at AppContainer.js:102)
    in RCTView (at View.js:71)
    in View (at AppContainer.js:122)
    in AppContainer (at renderApplication.js:34)

这是我的app.json

{
  "expo": {
    "sdkVersion": "25.0.0",
    "android": {
      "package": "hiking"
    },
    "name": "Hiking",
    "slug": "hiking",
    "version": "0.1.0",
    "isDetached": true,
    "detach": {
      "scheme": "exp56fa0b6664574a6ea12b193494508d48",
      "androidExpoViewUrl": "https://s3.amazonaws.com/exp-exponent-view-code/android-v2.3.0-sdk25.0.0-0c32461b-a7c6-4ddc-b85b-32a80c4f18d9.tar.gz"
    }
  }
}

和package.json

{
  "name": "Hiking",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "jest-expo": "25.0.0",
    "react-test-renderer": "16.2.0"
  },
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "test": "node node_modules/jest/bin/jest.js"
  },
  "jest": {
    "preset": "jest-expo"
  },
  "dependencies": {
    "expo": "^25.0.0",
    "react": "16.2.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-25.0.0.tar.gz",
    "react-native-cardview": "^1.1.5",
    "react-native-maps": "^0.20.1",
    "react-navigation": "^1.0.3",
    "rn-textinputlayout": "^1.0.5"
  }
}

react-native link react-native-cardview没有解决问题。 手动安装(如在readme中)并没有解决问题。 重建和重新启动服务器并没有解决问题。

我已经能够成功安装其他库(例如maps或textinputlayout)。

4 个答案:

答案 0 :(得分:1)

对于那些遇到同样问题的人,我设法通过完全改变项目的处理方式来修复它。

我所拥有的是一个用create-react-native-app制作的项目,我推出了它,用于XDE世博会。

我用react-native init创建了另一个项目,复制粘贴了我的.js文件和npm install,一切都运行得很完美。

世博XDE似乎没有正确处理react-native link指令,并且有点迷失。

无论如何,转到react-native init而不是弹出项目。

答案 1 :(得分:1)

只需在@Noitidart答案上添加一个,您在“ MainApplication.java”中的getPackages()就会像这样

[1,2,3,4,5,6,7,8,18,19,11,12,13,14,15,16,17,27,28,29]

答案 2 :(得分:0)

我成功使用了这个模块。它有一些自动链接问题(运行react-native link时。这是我必须要为Android修复它的东西:

  1. android/app/src/main/java/com/YOUR_APP_ID_HERE/MainApplication.java,移除import com.reactlibrary.RNCardViewPackage;并将其替换为import com.kishanjvaghela.cardview.RNCardViewPackage;

  2. 第一个修复应该是您所需要的,但在同一个文件中,请确保您在protected List<ReactPackage> getPackages() {条目中new RNCardViewPackage()

  3. android/settings.gradle中,请确保您拥有以下这些内容:

    包括':react-native-cardview'   project(':react-native-cardview')。projectDir = new File(rootProject.projectDir,'.. / node_modules / react-native-cardview / android')

  4. 最后我不认为这是这个模块的问题,但检查一下。如果您使用的是RN 0.47 plus,请转到node_modules目录并删除createJSModules,如果它在那里 - https://github.com/jsierles/react-native-audio/pull/216/files

答案 3 :(得分:0)

听起来lika webview版本有问题。您必须卸载当前的Webview版本并安装5.8.1版本。

执行以下步骤:

  1. react-native卸载react-native-webview

  2. react-native安装react-native-webview@5.8.1

有关https://github.com/react-native-community/react-native-webview/issues/580的更多信息