Search code examples
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

  • 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

    Edit

    Currently, both structures are required for a fully functional application that uses "react-native-google-mobile-ads". Issues have been open about this change and can be found here

    EXAMPLE
    // functional 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"
          }
        }
      },
      "react-native-google-mobile-ads": {
        "android_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx",
        "ios_app_id": "ca-app-pub-xxxxxxxx~xxxxxxxx"
      }
    }