在React Native中调用intermedialAd.load()方法时,应用程序崩溃



我正试图在我的项目中放置intermedialAd,但intermedialAD.load((正在崩溃应用程序。我的AdMob配置很好,广告横幅广告效果很好

使用的插件:@react native firebase/admob

这是代码:

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();
}}
/>    
)}
}

你好,我的朋友,我为你找到了一个解决方案app/build.gradle依赖项{。。。。实现("com.google.android.gms:播放服务广告:19.8.0"({force=true;}}

我维护react原生firebase,也许我可以解释为什么会发生这种情况,以及修复方法。

@react-native-firebase/admob自身使用时不会崩溃,带有InterinitialAds

然而,firebaseandroid-sdk和admob刚刚发布了一个突破性的更改版本(firebaseandrody-sdk为v27,admob为v20(,它移动了InterinitialAd包名称和(如果您有另一个admob依赖项(,其中gradle依赖项是用+的版本指定的,这允许突破性更改版本泄漏并破坏您的应用程序。

因此,正如其他人所评论的那样,将依赖关系固定在你的build.gradle中会修复你:

implementation("com.google.android.gms:play-services-ads:19.8.0") { force = true; }

详细信息请点击此处:https://github.com/invertase/react-native-firebase/issues/5127

react native firebase(包括admob模块(v11.3.1现在发布了此PR的内容,以解决以下问题:https://github.com/invertase/react-native-firebase/pull/5189

祝你的项目好运

Ei,我尝试了这个解决方案,似乎对第一次测试有效。https://github.com/invertase/react-native-firebase/discussions/5166

只是:变通方法app/build.gradle

实现("com.google.android.gms:播放服务广告:19.8.0"({force=true;}

最新更新