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;
2
Answers
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
I really don’t understand why this is documented so bad!
Here is my working code:
Or give this module a try:
npm i react-native-google-mobile-ads
https://www.npmjs.com/package/react-native-google-mobile-ads