Cannot Install "react-native-google-mobile-ads" to replace deprecated "expo-ads-admob"

According Admob - Expo Documentation and Expo SDK 45. Today we’re announcing the release of… | by Brent Vatne | Exposition, it is recommended to install react-native-google-mobile-ads as a replacement of existing expo-ads-admob package.

However, I tried to

  1. run expo install react-native-google-mobile-ads
  2. update the plugin parameter in app.json to include react-native-google-mobile-ads and my admob info, then
  3. run expo prebuild

it showed error
Package react-native-google-mobile-ads does not contain a valid config plugin

if I ignore the above step and directly apply the code
import mobileAds from 'react-native-google-mobile-ads';
mobileAds().initialize().then(adapterStatuses => {});
and
import { InterstitialAd, AdEventType, TestIds } from 'react-native-google-mobile-ads';
const adUnitId =TestIds.INTERSTITIAL;
const interstitial = InterstitialAd.createForAdRequest(adUnitId, {});
interstitial.load();

It showed error
null is not an object (evaluating RNAppModule.eventsNotifyReady)


I think react-native-google-mobile-ads does not have a guide to install with expo as mentioned in doc?
Thanks a lot!

Hey @polygon.ww, there isn’t currently a config plugin for this library so swapping the names of the libraries in your plugins array won’t work. Also, can you point me to where we mention an installation guide in our docs? AFAIK there isn’t one so we’d want to remove that from the docs.

Hi @adamjnav , in Expo SDK 45. Today we’re announcing the release of… | by Brent Vatne | Exposition posted a few days ago, under item " Deprecated many third-party service wrapper libraries in favor of official alternatives with config plugins.", it mentions that

Please refer to the respective documentation pages for suggestions on how to migrate to the recommended alternative libraries.

In Admob page (https://docs.expo.dev/versions/v45.0.0/sdk/admob/), it stated that

With EAS Build and Development Builds, you should use react-native-google-mobile-ads instead.

So I think react-native-google-mobile-ads is the recommended alternative library and should be compatible to expo…

Thanks!

hey there! you should be able to follow the installation instructions here: React Native Google Mobile Ads

this library requires you add the following to the root of your app.json (outside of the “expo” object):

// <project-root>/app.json
{
  "expo": {
    "// your other config": "goes here"
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
    "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
  }
}

let me know if this doesn’t work for you!

Hi @polygon.ww

Note that not everything that includes native code needs a config plugin. This looks like one that does not need one. So you should not add it to your plugins array in app.json.

Hi.
I think it would be nice if the docs explain how to install and configure react-native-google-mobile-ads with expo.
Thanks!

1 Like

hi there! it’s not feasible for us to add documentation to our own website about how to use every module, however it would make sense for there to be some information on the react-native-google-mobile-ads site specific to how to use it with expo managed projects. that said, you can follow the instructions on that site and instead of following the instructions at “For the changes to take effect, rebuild your project:” you would run eas build

1 Like

Thanks a lot for your help so much and I was able to install react-native-google-mobile-ads. Sorry that I misinterpreted the doc to install it as config plugin. It is okay now.

Thanks again. :grin:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.