react-native-youtube: Not working on Android
I’ve implemented successfully in ios but it not working in android. I’ve added API key but don’t know it correct or not because it accepted any value So I can’t sure it not working because wrong API key or my code. Can someone provide full tutorial on this implementation ?
<YouTube apiKey="AIzaSyCZs5LGQYP8EL8uQvvpO6SA-cFZs8kHw30" ref="youtubePlayer" videoId="tAawfiPaTbY" play={false} hidden={false} fullscreen={true} loop={false} style={{alignSelf: 'stretch', height: 300, backgroundColor: 'black', marginVertical: 10}} /> </View>
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 2
- Comments: 23 (6 by maintainers)
I had the same issue. I logged
onErrorand got aWarning: Native component for "ReactYouTube" does not existerror.I did run the
react-native linkbut it seems like it didn’t fix all issues for me.Im my
MainApplicationI needed to add theReactNativeYouTubeto the react packages list. I use the following versions (from my package.json):And my MainApplication now looks like this:
@victor-axelsson your solution works! But you forgot to mention you need to include at the top of MainApplication.java:
Thanks ❤️
Hi, in case anyone is having this compiling error: package com.inprogress.reactnativeyoutube does not exist error, I finally could make it work in Android. From @madhuA14 I realized the linking is not adding the dependency to compile. Obviously I did before
react-native linkandrnpm linkas stated in README, with no success. So:app/build.gradle
Btw both
react-native linkandrnpm linkcommands should target this module:react-native link react-native-youtubernpm link react-native-youtubeOtherwise you will link again ALL your native modules.Versions: react-native: 0.46.4 react-native-youtube: 1.0.1
I had same issue solved with below steps,
settings.gradle include ‘:node_modules’ include ‘:react-native-youtube’ project(‘:react-native-youtube’).projectDir = new File(rootProject.projectDir, ‘/node_modules/react-native-youtube/android’)
app/build.gradle compile project(‘:react-native-youtube’)
addPackage(new ReactNativeYouTube()) in your MyReactActivity.
Here is what worked for me:
react-native linkin android/settings.gradle:
add following before include ‘:app’
in android/app/build.gradle:
add following in dependencies:
In MainApplication.java:
import com.inprogress.reactnativeyoutube.ReactNativeYouTube;add following in return Arrays.<ReactPackage>asList:
in package.json:
"react-native-fs": "^2.8.1",@bbeckk Did you connected the libraries with
react-native link?@choungchamnab Try to log any error that you might get with the
onErrorevent callback. Nevertheless its a good practice to useonErroron such a module that depends on external factors like a correct API Key or the existence of a YouTube app on the devicePlus you just published your API Key on the internet