恢复 AdMob RewardedVideoAd 时崩溃

Crash when resume an AdMob RewardedVideoAd(恢复 AdMob RewardedVideoAd 时崩溃)

本文介绍了恢复 AdMob RewardedVideoAd 时崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用最新的 AdMob 版本 15.0.0,我在从另一个 Activity 返回后尝试恢复 RewardedVideoAd 时遇到崩溃.

With the last AdMob version, 15.0.0, I getting a crash when try to resume a RewardedVideoAdafter return from another Activity.

 java.lang.ClassCastException: com.google.ads.mediation.admob.AdMobAdapter cannot be cast to com.google.android.gms.ads.mediation.m
     at com.google.android.gms.ads.internal.mediation.client.y.a(:com.google.android.gms.dynamite_dynamitemodulesa12.5.29 (000308-192802242):262)
     at com.google.android.gms.ads.internal.reward.c.b(:com.google.android.gms.dynamite_dynamitemodulesa12.5.29 (000308-192802242):54)
     at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.dynamite_dynamitemodulesa12.5.29 (000308-192802242):57)
     at android.os.Binder.transact(Binder.java:361)
     at com.google.android.gms.internal.zzev.zzb(Unknown Source)
     at com.google.android.gms.internal.zzaez.zzc(Unknown Source)
     at com.google.android.gms.internal.zzafk.resume(Unknown Source)
     at com.byteghoul.grimdefender.GhoulAdsAndroid3.onResume(GhoulAdsAndroid3.java:411)
     at com.byteghoul.grimdefender.AndroidLauncher.onResume(AndroidLauncher.java:437)
     at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1198)
     at android.app.Activity.performResume(Activity.java:5530)
     at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3047)
     at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3086)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:136)
     at android.app.ActivityThread.main(ActivityThread.java:5586)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:515)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
     at dalvik.system.NativeStart.main(Native Method)

集成似乎没问题,我只是按照 AdMob 文档做的没什么奇怪的.

The integration seems ok, I just follow the AdMob docs doing nothing strange.

我检查了 Google AdMob github 示例,也遇到了同样的错误.

I checked the Google AdMob github sample and I got the same error.

有关更多信息,这是我的 RewardedVideo 包装器:

For futher information, here are my RewardedVideo wrapper:

class VideoAd @Inject constructor(@Named(BaseActivity.BaseModule.ACTIVITY_CONTEXT) private val context: Context) {

private var isAlreadyPrepared: Boolean = false
private lateinit var rewardedVideoAd: RewardedVideoAd
private val customListener: CustomVideoListener = CustomVideoListener()
private var adsListener: AdsListener = object : AdsListener {}
val isVideoLoaded: Boolean
    get() = rewardedVideoAd.isLoaded

fun prepare(listener: AdsListener) {
    adsListener = listener
    if (isAlreadyPrepared) {
        return
    }
    rewardedVideoAd = MobileAds.getRewardedVideoAdInstance(context)
    rewardedVideoAd.rewardedVideoAdListener = customListener
    val adRequest: AdRequest = AdRequest.Builder()
        .addTestDevice(ADS_ID_TEST_DEVICE)
        .addTestDevice(ADS_ID_TEST_DEVICE_2)
        .build()
    rewardedVideoAd.loadAd(VIDEO_ADS_ID, adRequest)
    isAlreadyPrepared = true
}

fun show() {
    if (isVideoLoaded) {
        rewardedVideoAd.show()
    } else {
        logNonFatalException("Video Ad not loaded successfully before show it")
        adsListener.onVideoAdNotLoaded()
    }
}

fun onPauseActivity() {
    rewardedVideoAd.pause(context)
}

fun onResumeActivity() {
    rewardedVideoAd.resume(context)
}

fun onDestroyActivity() {
    rewardedVideoAd.destroy(context)
}

private inner class CustomVideoListener : RewardedVideoAdListener {
    override fun onRewardedVideoAdClosed() {
        adsListener.onAdsFinishedSuccessfully()
    }

    override fun onRewardedVideoAdLeftApplication() {
    }

    override fun onRewardedVideoAdLoaded() {
    }

    override fun onRewardedVideoAdOpened() {
    }

    override fun onRewardedVideoCompleted() {
    }

    override fun onRewarded(reward: RewardItem?) {
        adsListener.onAdsFinishedSuccessfully()
    }

    override fun onRewardedVideoStarted() {
    }

    override fun onRewardedVideoAdFailedToLoad(p0: Int) {
    }
}

}

推荐答案

在google bug tracking中搜索,貌似这是15.0.0版本的bug:

Searching in google bug tracking seems that this is a bug of the 15.0.0 version:

https://groups.google.com/forum/#!topic/google-admob-ads-sdk/XtVZFQ-nl98

可能的解决方案是:

  • 将版本降级到以前的稳定版本.
  • 等到谷歌发布修复.

这篇关于恢复 AdMob RewardedVideoAd 时崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:恢复 AdMob RewardedVideoAd 时崩溃

基础教程推荐