skip to Main Content

I am creating a react native app, In my Emulator google mobile ads (Rewarded testing ads) working very well. but when I test the app on my real device(Personal phone) then the rewarded Ads not work, it crashed the app, only banner ads working on real device.

What is the problem, could anyone please reply with a solution?
Thank you in advance

Here below is the code I am using for rewarded ads

import React, { useState, useEffect } from "react";
import { View, Button, Text, ScrollView, } from 'react-native'
import { RewardedAd, RewardedAdEventType, TestIds } from 'react-native-google-mobile-ads';

const adUnitId = __DEV__ ? TestIds.REWARDED : 'ca-app-pub-3940256099942544/5224354917';

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

const Testing = ({ navigation }) =>{
    const [loaded, setLoaded] = useState(false);

    useEffect(() => {
      const unsubscribeLoaded = rewarded.addAdEventListener(RewardedAdEventType.LOADED, () => {
        setLoaded(true);
        rewarded.show();
      });
      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();
      };
    }, []);
  
    return (
        <ScrollView>
        <View style={{flex:1, justifyContent : 'center',alignItems : 'center'}}>
        <Text> 
        Lorem Ipsum is simply dummy text of the printing and typesetting industry.
        Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,
         </Text>
        <Button onPress = {() => navigation.navigate('First')} title='Next Screen'></Button>
           </View>
        </ScrollView>
    )
    
    }
    export default Testing;

Please check the image screenshot-
enter image description here enter image description here enter image description here enter image description here

2

Answers


  1. react-native-google-mobile-ads maintainer here

    You will want to use version 8.1.2 of the module which has a fix I just made to avoid reflective use of the admob SDKs so that proguard doesn’t have problems determining what to keep and we don’t have problems with obfuscated names post-proguard

    https://github.com/invertase/react-native-google-mobile-ads/issues/241#issuecomment-1275530015

    Login or Signup to reply.
  2. I really don’t understand why this is documented so bad!

    Here is my working code:

     import { InterstitialAd,BannerAd, TestIds,setTestDeviceIDAsync } from '@react-native-admob/admob';
    
    componentDidMount() {
        const ad = InterstitialAd.createAd('ca-app-pub-3940256099942544/1033173712', {
              loadOnDismissed: true,
              requestOptions: {
                requestNonPersonalizedAdsOnly: true,
              },
            });
            ad.addEventListener('adLoaded', () => {
             ad.show();
            });
            ad.addEventListener('adDismissed', () => {
        
            });
    }
    

    Or give this module a try:
    npm i react-native-google-mobile-ads

    https://www.npmjs.com/package/react-native-google-mobile-ads

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