React-native-admob: _reactNativeAdmob.AdMobInterstitial... is not a function

Created on 19 Aug 2016  路  9Comments  路  Source: sbugert/react-native-admob

Hello!

I'm desperately trying to get this to work. I'm using latest React Native (0.31.0). Even with fresh, basic setup. I'm getting the same error when running on Android emulator:

Tried 'react-native link' and said successfully linked. No build errors or warnings.

Warning: Native component for "RNAdMob" does not exist
_reactNativeAdmob.AdMobInterstitial.setTestDeviceID is not a function

Thanks!

Relevant bits of code below.

import { AdMobInterstitial, AdMobBanner } from 'react-native-admob';

import React, { Component } from 'react'
import {
  AppRegistry,
  StyleSheet,
  Text,
  TouchableHighlight,
  View,
  Navigator,
} from 'react-native'

class BestOdds extends Component {
  constructor() {
    super();
  }
  componentDidMount() {
    AdMobInterstitial.setTestDeviceID('EMULATOR');
    AdMobInterstitial.setAdUnitID('ca-app-pub-9195087403068123/7447384695');
  }
  componentWillUnmount() {
    AdMobInterstitial.removeAllListeners();
  }
  showInterstital() {
    AdMobInterstitial.showAd((error) => error && console.log(error));
  }
  render( etc... )
});

AppRegistry.registerComponent('BestOdds', () => BestOdds);

Most helpful comment

First off, thanks for the quick reply. You saying:

With that error it seems like it is not successfully linked.

I was able to find the issue. I'm coming from web to native via react native, so the native libraries are still a magical wonderland to me. I inspected the files per your manual instructions and found these differences:

In settings.gradle:

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

Instead of:

include ':RNAdMob', ':app'
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')

In build.gradle:
compile project(':react-native-admob')
Replaced with:
compile project(':RNAdMob')

In app/src/main/java/com/{appname}/MainApplication.java (btw, the readme doesn't have the full path for dummies like me), I added:
new RNAdMobPackage()

However, this was fine in app/src/main/java/com/{appname}/MainActivity.java:
import com.sbugert.rnadmob.RNAdMobPackage;
But I also had to add that to app/src/main/java/com/{appname}/MainApplication.java.

So, it seems like the linking wasn't working. I'm on a Windows dev environment, so that could be permissions.

Also, I've noticed with any packages that have links, that you have to run react-native run-android with NO js server or emulator running first before you can run-android with an emulator running, as windows locks the files for adb. You have to run, let it fail at installDebug, start your emulator, and run again. I'm calling Bill Gates about it now. I hope that helps you and/or someone!

Also, my code as presented had to be changed to:

showInterstital() {
    AdMobInterstitial.requestAd(AdMobInterstitial.showAd);
}

After all that and a react-native start --reset-cache, success! https://www.dropbox.com/s/qeh9ncu4zhik02g/Screenshot_20160819-115800.png?dl=0

All 9 comments

That's weird, it works for me with the same setup.
With that error it seems like it is not successfully linked. Are we talking about android or both platforms?

Maybe try the good ol' rm -rf node_modules && npm install?

First off, thanks for the quick reply. You saying:

With that error it seems like it is not successfully linked.

I was able to find the issue. I'm coming from web to native via react native, so the native libraries are still a magical wonderland to me. I inspected the files per your manual instructions and found these differences:

In settings.gradle:

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

Instead of:

include ':RNAdMob', ':app'
project(':RNAdMob').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-admob/android')

In build.gradle:
compile project(':react-native-admob')
Replaced with:
compile project(':RNAdMob')

In app/src/main/java/com/{appname}/MainApplication.java (btw, the readme doesn't have the full path for dummies like me), I added:
new RNAdMobPackage()

However, this was fine in app/src/main/java/com/{appname}/MainActivity.java:
import com.sbugert.rnadmob.RNAdMobPackage;
But I also had to add that to app/src/main/java/com/{appname}/MainApplication.java.

So, it seems like the linking wasn't working. I'm on a Windows dev environment, so that could be permissions.

Also, I've noticed with any packages that have links, that you have to run react-native run-android with NO js server or emulator running first before you can run-android with an emulator running, as windows locks the files for adb. You have to run, let it fail at installDebug, start your emulator, and run again. I'm calling Bill Gates about it now. I hope that helps you and/or someone!

Also, my code as presented had to be changed to:

showInterstital() {
    AdMobInterstitial.requestAd(AdMobInterstitial.showAd);
}

After all that and a react-native start --reset-cache, success! https://www.dropbox.com/s/qeh9ncu4zhik02g/Screenshot_20160819-115800.png?dl=0

I have a similar issue for iOS and I can't find a way to fix it.
Banners works fine, but Interstitial are failing.

This is my code:

import { AdMobInterstitial } from 'react-native-admob';

AdMobInterstitial.setAdUnitID(adMobConfig.interstitialUnitId);
AdMobInterstitial.setTestDeviceID('EMULATOR');
AdMobInterstitial.requestAd(AdMobInterstitial.showAd);

screen shot 2016-10-22 at 02 52 30

@alexmngn did you by any chance got to fix it ?

Same Problem like @alexmngn in my case. Intersitital - ID is valid - anyone has a fix for that?

Try to send callback argument like this:

AdMobInterstitial.showAd((error)=>{if(error) Alert.alert(error)});

Hi i got same issue with alexmngn, does anyone have solution ?

@gopsdepth when i use AdMobInterstitial.showAd((error)=>{if(error) Alert.alert(error)});, it give me alert like "Ad is not ready" . After this I am not getting that error . I doubt , ads will be visible in production or not.

@sachinwak If you get such error, I think the ads will not be shown. Try to call AdMobInterstitial.requestAd and take some time before calling AdMobInterstitial.showAd or use AdMobInterstitial.requestAd(AdMobInterstitial.showAd);. I think that we don't need to send callback to AdMobInterstitial.showAd in latest version anymore.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brkrtp picture brkrtp  路  3Comments

xvlm picture xvlm  路  5Comments

kanekotic picture kanekotic  路  6Comments

giladno picture giladno  路  6Comments

shinriyo picture shinriyo  路  3Comments