skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    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
    

  2. I faced the same error, and managed to resolve the issue by following the below steps:

    1. Adjust app.json

    • Before the "react-native-google-mobile-ads" was at the root level.
    • Now the "react-native-google-mobile-ads" should be moved at root > expo > extra
    • more details here
    EXAMPLE
    // old app.json
    {
      "expo": {
      // ...
      },
      "react-native-google-mobile-ads": {
        "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
        "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
      }
    }
    
    // new app.json
    {
      "expo": {
        // ...
        "extra": {
          "react-native-google-mobile-ads": {
            "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
            "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
          }
        }
      }
    }
    

    2. Update react-native-google-mobile-ads library

    The issue is resolved by version 14, "react-native-google-mobile-ads": "^14.0.0", which can be found here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search