react-nativeexpoadmob

react-native-google-mobile-ads gives error on expo ios build


When I try to import react-native-google-mobile-ads, Expo gives multiple errors in my iOS build.

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'RNGoogleMobileAdsModule' could not be found

Invariant Violation: "main" has not been registered.

I reconfigured my ios build and tried to change a few things in the ios folder but I kept getting the same error


Solution

  • First of all, I removed the react-native-google-mobile-ads component from app.config.js file from expo component and changed it as follows:

    'react-native-google-mobile-ads': {
    ios_app_id: 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyy',
    android_app_id: 'ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyy',
    },
    

    Then I added the following to the Info.plist file in the ios folder:

    <key>GADApplicationIdentifier</key>
    <string>ca-app-pub-xxxxxxxxxxxxxxxxxxxxxxxx~yyyyyyyyyyyyyy</string>
    

    Then I added the following to the AppDelegate.m file, also in the ios folder:

    #import <GoogleMobileAds/GoogleMobileAds.h>
    

    Finally, I ran the following in the terminal:

    cd ios
    rm -rf Pods
    rm -rf Podfile.lock
    pod install
    cd..
    expo run:ios