首页 > 解决方案 > 将库添加到 react-native 应用程序时出现 react-native-youtube 库不变错误

问题描述

我正在使用 React Native 创建一个电影和电视节目项目,并尝试为每个来自 YouTube 的预告片添加视频,但我收到了这个错误。

Invariant Violation: requireNativeComponent: "ReactYouTube" was not found in the UIManager.

这就是我目前正在做的:错误图片

import YouTube from 'react-native-youtube';

...

state = {
   isReady: false,
    status: "",
    quality: "",
    error: ""
}

...

          <YouTube
            apiKey="AIzaSyCce0TNBZDyCCP62B2P8EkTfgjgp20ZqOA"
            videoId="jKCj3XuPG8M" // The YouTube video ID
            play // control playback of video with true/false
            fullscreen={false} // video should play in fullscreen or inline
            loop={false} // control whether the video should loop when ended
            onReady={e => this.setState({ isReady: true })}
            onChangeState={e => this.setState({ status: e.state })}
            onChangeQuality={e => this.setState({ quality: e.quality })}
            onError={e => this.setState({ error: e.error })}
            style={{ alignSelf: "stretch", height: 300 }}
          />

我尝试将 ReactNativeYoutube 包直接添加到MainApplication.java

import com.inprogress.reactnativeyoutube.ReactNativeYouTube;

...

packages.add(new ModuleRegistryAdapter(mModuleRegistryProvider));

settings.gradle

include ':react-native-youtube'

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

并且还到build.gradle

implementation project(':react-native-youtube')

但是我仍然遇到同样的错误,想知道是否有人遇到过同样的错误并有解决方案

标签: androidreact-nativeandroid-youtube-apiexpo

解决方案


当软件包安装未正确完成时,可能会出现此类错误。通过检查确认您是否在应用程序文件夹中正确安装了软件包

还有一件事,对于 Android 用户,:该组件的 Android 实现需要在设备上安装 YouTube 应用程序。否则将触发错误事件SERVICE_MISSING/SERVICE_DISABLED.


推荐阅读