Search code examples
androidreactjsreact-nativeadmobads

Admob React Native google mobile ads not working on real device, Rewarded ads working on Emulator but crashing on real device


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


Solution

  • 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