2

在上一个 AdMob 版本中,15.0.0当我尝试RewardedVideoAd从另一个 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_dynamitemodulesa@12529004@12.5.29 (000308-192802242):262)
     at com.google.android.gms.ads.internal.reward.c.b(:com.google.android.gms.dynamite_dynamitemodulesa@12529004@12.5.29 (000308-192802242):54)
     at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.dynamite_dynamitemodulesa@12529004@12.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 文档做的没什么奇怪的。

我检查了 Google AdMob github 示例,我得到了同样的错误。

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

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) {
    }
}

}

4

2 回答 2

3

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

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

可能的解决方案是:

  • 将版本降级到以前的稳定版本。
  • 等到谷歌推出修复程序。
于 2018-04-21T19:33:24.003 回答
0

我遇到了同样的问题,我将 AdMob 版本 15.0.0 更改为 15.0.1 并且效果很好。

于 2018-07-04T09:10:00.620 回答