android - 将库添加到 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')
但是我仍然遇到同样的错误,想知道是否有人遇到过同样的错误并有解决方案
解决方案
当软件包安装未正确完成时,可能会出现此类错误。通过检查确认您是否在应用程序文件夹中正确安装了软件包
还有一件事,对于 Android 用户,:该组件的 Android 实现需要在设备上安装 YouTube 应用程序。否则将触发错误事件SERVICE_MISSING/SERVICE_DISABLED.
推荐阅读
- bash - 在 bash 中解析结果
- spring-boot - feign.RetryableException:读取执行 GET 超时
- angular - Angular4 - 无效的不记名令牌,令牌= null
- angular - 数组上的过滤函数无法第二次返回结果
- gatling - 超时异常后,加特林活跃用户下降到负数以进行更长时间的运行
- webrtc - ICE 候选人仅从一个网络接口收集
- php - 使用 PHP、SQL SERVER 和 AJAX 的动态相关选择框
- arrays - 为什么加号和一元加号在数组语法中表现奇怪?
- scala - 从 CSV Gatling 馈送器获取值以创建 POST 请求正文
- python - 为什么(或为什么不)将 Anaconda 添加到路径?