【发布时间】:2020-07-06 22:23:17
【问题描述】:
我正在使用 React Native 创建一个电影和电视节目项目,并尝试为每个来自 YouTube 的预告片添加视频,但出现此错误。
Invariant Violation: requireNativeComponent: "ReactYouTube" was not found in the UIManager.
这就是我目前正在做的事情:Error Image
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 }}
/>
我试过直接在MainApplication.java添加ReactNativeYoutube包
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 上运行,您只需从您的
package.json中删除"postinstall": "cd ios && pod install && cd .."。因为错误是ios错误而不是android错误。 -
Expo 可能是问题所在,因为原生模块。所以我会尝试 React Native CLI。如果这不起作用,我建议查看这些问题github.com/davidohayon669/react-native-youtube/…。
-
@BasvanderLinden 谢谢你,我想试试你所说的关于从
package.json中删除这个"postinstall": "cd ios && pod install && cd .."但这不存在,或者你的意思是我应该添加它? -
我以为您使用的是来自github.com/davidohayon669 的示例项目。如果
postinstall不在,你可以忽略我说的。
标签: android react-native android-youtube-api expo