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)

Most upvoted comments

I had the same issue. I logged onError and got a Warning: Native component for "ReactYouTube" does not exist error.

I did run the react-native link but it seems like it didn’t fix all issues for me.

Im my MainApplication I needed to add the ReactNativeYouTube to the react packages list. I use the following versions (from my package.json):

    "react": "16.0.0-alpha.12",
    "react-native": "0.46.1",
    "react-native-youtube": "^1.0.0-beta.1",

And my MainApplication now looks like this:

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    public boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new ReactNativeYouTube(), /// <- here I added the package, which wasn't added before.
          new MainReactPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
    return mReactNativeHost;
  }

  @Override
  public void onCreate() {
    super.onCreate();
    SoLoader.init(this, /* native exopackage */ false);
  }
}

@victor-axelsson your solution works! But you forgot to mention you need to include at the top of MainApplication.java:

import com.inprogress.reactnativeyoutube.ReactNativeYouTube;

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 link and rnpm link as stated in README, with no success. So:

app/build.gradle

[...]
dependencies {
  compile project(':react-native-youtube')
[...]

Btw both react-native link and rnpm link commands should target this module: react-native link react-native-youtube rnpm link react-native-youtube Otherwise 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 link

in android/settings.gradle:

add following before include ‘:app’

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

in android/app/build.gradle:

add following in dependencies:

compile project(':react-native-youtube')
compile project(':react-native-fs')

In MainApplication.java:

import com.inprogress.reactnativeyoutube.ReactNativeYouTube;

add following in return Arrays.<ReactPackage>asList:

new ReactNativeYouTube(),
new RNFSPackage()

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 onError event callback. Nevertheless its a good practice to use onError on such a module that depends on external factors like a correct API Key or the existence of a YouTube app on the device

Plus you just published your API Key on the internet