React-native-admob: AdMobInterstitial undefined is not a function

Created on 5 Jun 2018  路  3Comments  路  Source: sbugert/react-native-admob

import { AdMobInterstitial } from 'react-native-admob';
...
componentDidMount() {
      AdMobInterstitial.setTestDeviceID('EMULATOR').catch(error => console.warn(error));
      AdMobInterstitial.setAdUnitID(admobInterstitialUnitId).catch(error => console.warn(error));
      AdMobInterstitial.requestAd().catch(error => console.warn(error));
  }

I am getting error below. All i have done like example codes here but it is not working. I have checked the build.gradle, settings.gradle, MainApplication.java. All files are same with example of this page.

screenshot_1528182380

Most helpful comment

You can put Sample ad Unit ID for testing or Original ad Unit Id which you might be created
I use sample ad unit Id here,

componentWillMount() {
AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
}

You can refer to this link:
https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

I have used your example. And exactly the code (replacing the admobUnitId with mine). I am still getting the error similar to the above (undefined is not a function) - see attached snapshot.

Very strange indeed.
react-native-admob:2.0.0-beta.5
image

EDITED: I have fixed the problem
Basically, I still need to link the native code even while using the simulator (bugger me!)
I forgot to do all the android native library linkage. Once I complete all the manual step, everything compiled and run perfectly. My mistake!
Below is an example. Reply to this message if you want more details!

image

All 3 comments

I am getting the same error too.

Edit: I've fixed it.

My code;

AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());

You can put Sample ad Unit ID for testing or Original ad Unit Id which you might be created
I use sample ad unit Id here,

componentWillMount() {
AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
}

You can refer to this link:
https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

You can put Sample ad Unit ID for testing or Original ad Unit Id which you might be created
I use sample ad unit Id here,

componentWillMount() {
AdMobInterstitial.setAdUnitID('ca-app-pub-3940256099942544/1033173712');
AdMobInterstitial.setTestDevices([AdMobInterstitial.simulatorId]);
AdMobInterstitial.requestAd().then(() => AdMobInterstitial.showAd());
}

You can refer to this link:
https://react-native-solutions.blogspot.com/2018/07/how-to-create-react-native-app-with.html

I have used your example. And exactly the code (replacing the admobUnitId with mine). I am still getting the error similar to the above (undefined is not a function) - see attached snapshot.

Very strange indeed.
react-native-admob:2.0.0-beta.5
image

EDITED: I have fixed the problem
Basically, I still need to link the native code even while using the simulator (bugger me!)
I forgot to do all the android native library linkage. Once I complete all the manual step, everything compiled and run perfectly. My mistake!
Below is an example. Reply to this message if you want more details!

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jonigl picture jonigl  路  4Comments

ozmaat picture ozmaat  路  3Comments

danvass picture danvass  路  6Comments

priya-vr picture priya-vr  路  3Comments

EpicNem picture EpicNem  路  6Comments