With the last AdMob version, 15.0.0
, I getting a crash when try to resume a RewardedVideoAd
after 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_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)
The integration seems ok, I just follow the AdMob docs doing nothing strange.
I checked the Google AdMob github sample and I got the same error.
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) {
}
}
}
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
Possible solutions are:
- Downgrade version to a previous stable one.
- Wait until google launch a fix.
I had the same problem, I changed the AdMob version 15.0.0 to 15.0.1 and it works well .
来源:https://stackoverflow.com/questions/49959466/crash-when-resume-an-admob-rewardedvideoad