I am trying to place interstitialAd in my project but the interstitialAd.load(); is crashing the app. My AdMob config is fine ad Banner ads are working perfectly .
Used Plugin: @react-native-firebase/admob
Here is the code:
import { Button, View } from 'react-native';
import { InterstitialAd, AdEventType, TestIds } from '@react-native-firebase/admob';
export default class InterstitialAdUnit extends React.Component {
constructor(props) {
super(props);
}
showInterstitialAd = () => {
const interstitialAd = InterstitialAd.createForAdRequest(TestIds.INTERSTITIAL);
interstitialAd.onAdEvent((type, error) => {
if (type === AdEventType.LOADED) {
interstitialAd.show();
}
});
interstitialAd.load();
}
render() {
return (
<Button
title="Show Interstitial"
onPress={() => {
this.showInterstitialAd();
}}
/>
)}
}
hello my friend i found a solution for you app/build.gradle dependencies {.... implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; } }
Ei, I try this solution and seems works for the first test. https://github.com/invertase/react-native-firebase/discussions/5166
Just: workaround app/build.gradle
implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; }
I maintain react-native-firebase and maybe I can explain why this happened, as well as the fix.
@react-native-firebase/admob
will not crash if used by itself, with InterstitialAds
However, firebase-android-sdk and the admob just issued a breaking change release (v27 for firebase-android-sdk, v20 for admob) that moves InterstitialAd package names and if you have another admob dependency where the gradle dependency was specified with a version of +
, that allows the breaking change version to leak through and break your app.
So pinning the dependency in your build.gradle
as others have commented will fix you:
implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; }
Full details here: https://github.com/invertase/react-native-firebase/issues/5127
react-native-firebase (including the admob module) v11.3.1 is releasing now with contents of this PR to fix things: https://github.com/invertase/react-native-firebase/pull/5189
Good luck with your projects
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.