Migrating Expo AdMob to react-native-google-mobile-ads

Hello. I’m upgrading to Expo SDK 46.

Since Admob is removed in SDK46, I’m having a hard time migrating to the recommended library as stated in the docs. I try to follow the steps to setup react-native-google-mobile-ads in Expo but I always end up with this error

Invariant Violation: requireNativeComponent: "RNGoogleMobileAdsBannerView" was not found in the UIManager.

when showing the Banner

      <BannerAd
        unitId={BannerAdUnitID}
        size={BannerAdSize.FULL_BANNER}
        requestOptions={{
          requestNonPersonalizedAdsOnly: true,
        }}

I run the code via npx expo start --dev-client. Can anyone help? I can provide needed details. Thank you so much.

Things I tried:

  • expo prebuild
  • running eas build --profile development --platform android
    – which produces
[stderr] /home/expo/workingdir/build/android/app/src/debug/AndroidManifest.xml:16:85-105 Error:
[stderr] 	Attribute meta-data#com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT@value value=(true) from AndroidManifest.xml:16:85-105
[stderr] 	is also present at [:react-native-google-mobile-ads] AndroidManifest.xml:19:13-34 value=(false).
[stderr] 	Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:16:5-107 to override.
[stderr] FAILURE: Build failed with an exception.
[stderr] * What went wrong:
[stderr] Execution failed for task ':app:processDebugMainManifest'.
[stderr] > Manifest merger failed : Attribute meta-data#com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT@value value=(true) from AndroidManifest.xml:16:85-105
[stderr]   	is also present at [:react-native-google-mobile-ads] AndroidManifest.xml:19:13-34 value=(false).
[stderr]   	Suggestion: add 'tools:replace="android:value"' to <meta-data> element at AndroidManifest.xml:16:5-107 to override.
[stderr] * Try:
[stderr] > Run with --stacktrace option to get the stack trace.
[stderr] > Run with --info or --debug option to get more log output.
[stderr] > Run with --scan to get full insights.
[stderr] * Get more help at https://help.gradle.org
[stderr] BUILD FAILED in 7m 45s

I’m in Managed Workflow btw, should I switch to Bare workflow in order for this to work?

Hi @palaganaskurl

I have not used Admob myself, but maybe I can clarify things a little.

Note that expo prebuild generate the native code, so it is basically the same as the old expo eject. For a managed project you do not need to run expo prebuild. It is run for you during the build as you can see in the build logs.

It looks like this is also present in expo-admob. Is it possible you still have that installed in addition to react-native-google-mobile-ads? If so, try uninstalling expo-admob and see if the build works.

Also, you might want to undo the changes made by expo prebuild: expo.fyi/prebuild-cleanup