0

I am creating a project on a React Native application, and I am using Expo. I would like to add ads, so I'm using Google Ad Mob. So I created my account on the site. I have a problem and it's been a long time that I can't solve it. I have this error: ` ERROR Invariant Violation: Your JavaScript code tried to access a native module that doesn't exist.

If you're trying to use a module that is not supported in Expo Go, you need to create a development build of your app. See https://docs.expo.dev/development/introduction/ for more info. ERROR Invariant Violation: Failed to call into JavaScript module method AppRegistry.runApplication(). Module has not been registered as callable. Registered callable JavaScript modules (n = 11): Systrace, JSTimers, HeapCapture, SamplingProfiler, RCTLog, RCTDeviceEventEmitter, RCTNativeAppEventEmitter, GlobalPerformanceLogger, JSDevSupportModule, HMRClient, RCTEventEmitter. A frequent cause of the error is that the application entry file path is incorrect. This can also happen when the JS bundle is corrupt or there is an early initialization error when loading React Native.`

here is my package.json:

    {
      "name": "front",
      "version": "1.0.0",
      "scripts": {
      "start": "expo start --dev-client",
      "android": "expo run:android",
      "ios": "expo run:ios",
      "web": "expo start --web"
    },
    "dependencies": {
      "@expo/vector-icons": "^13.0.0",
      "@react-navigation/drawer": "^6.5.7",
      "@react-navigation/native": "^6.1.2",
      "@react-navigation/native-stack": "^6.9.8",
      "axios": "^1.2.2",
      "expo": "~47.0.12",
      "expo-build-properties": "~0.4.1",
      "expo-dev-client": "~2.0.1",
      "expo-secure-store": "~12.0.0",
      "expo-splash-screen": "~0.17.5",
      "expo-status-bar": "^1.4.2",
      "react": "18.1.0",
      "react-native": "0.70.5",
      "react-native-animated-loader": "^1.0.0",
      "react-native-gesture-handler": "~2.8.0",
      "react-native-google-mobile-ads": "^9.1.1",
      "react-native-infinite-scroll-view": "^0.4.5",
      "react-native-keyboard-aware-scroll-view": "^0.9.5",
      "react-native-reanimated": "~2.12.0",
      "react-native-safe-area-context": "4.4.1",
      "react-native-screens": "~3.18.0",
      "react-native-toast-message": "^2.1.5",
      "react-navigation": "^4.4.4",
      "react-router": "^6.6.2"
    },
    "devDependencies": {
      "@babel/core": "^7.12.9",
      "react-native-secure-store": "^1.0.3"
    },
    "private": true
    }

and here is the file in which I use ad mob:

    import React, { useState } from "react";
    import { View, Text, Button, Alert, TouchableOpacity } from 'react-native';
    import { SafeAreaView } from "react-native-safe-area-context";
    import { RewardedAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';

    const adUnitId = __DEV__ ? TestIds.REWARDED : 'ca-app-pub-blablabla';

    const rewarded = RewardedAd.createForAdRequest(adUnitId, {
     requestNonPersonalizedAdsOnly: true,
     keywords: ['fashion', 'clothing'],
    });

    const Video = () => {

     const [loaded, setLoaded] = useState(false);

     useEffect(() => {
       const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
       setLoaded(true);
      });
     const unsubscribeEarned = rewarded.addAdEventListener(
       RewardedAdEventType.EARNED_REWARD,
       reward => {
         console.log('User earned reward of ', reward);
       },
     );

    // Start loading the rewarded ad straight away
     rewarded.load();

    // Unsubscribe from events on unmount
     return () => {
       unsubscribeLoaded();
       unsubscribeEarned();
     };
   }, []);

   if (!loaded) {
     return null;
   }
  
    return (
      <View style={{alignItems: "center", justifyContent: "center"}}>
        <TouchableOpacity style={{borderColor: "blue", padding: 30}}>
            <Text onPress={() => rewarded.show()}>Watch Rewarded Ad</Text>
        </TouchableOpacity>
      </View>
    );
    };

export default Video;

I re-installed the nodes modules, I added this to my app.json file:

    "plugins": [
      [
        "expo-build-properties",
        {
          "android": {
            "compileSdkVersion": 31,
            "targetSdkVersion": 31,
            "buildToolsVersion": "31.0.0"
          },
          "ios": {
            "deploymentTarget": "13.0"
          }
        }
      ]
    ]
  },
  "react-native-google-mobile-ads": {
    "android_app_id": "ca-app-pub-2973173763441523~2444055698",
    "ios_app_id": "ca-app-pub-2973173763441523~5693853805"
  }

I followed the installation guide, so if anyone can help me to use Ad mob I would love it, thanks!

Knowz
  • 1
  • you need to create the dev app first using the latest library you added, create by using eas -p android --profile development, then to start it using expo start --dev-client – bagi2info.com Feb 26 '23 at 10:53

0 Answers0