Googleads-mobile-unity: Second rewarded ad not shown in Android

Created on 26 Sep 2017  路  15Comments  路  Source: googleads/googleads-mobile-unity

Hi there!

We're experiencing an issue with Rewarded Video Ads in Android, when using the Unity plug-in.

The first ad is shown without any problem. But if we request a second ad, it can't be shown. The method "rewardBasedVideo.IsLoaded()" returns true, so we call "rewardBasedVideo.Show()". This is the flow:

  • We invoke rewardBasedVideo.LoadAd() to load the ad at the beginning.
  • When it's time to show the ad, we check if it's loaded invoking rewardBasedVideo.IsLoaded().
  • If IsLoaded returns true, we invoke rewardBasedVideo.Show()

Connecting the phone to Android Studio to check the logs, we can see a NullPointerException when we invoke Show for the second ad. Here is the stack trace:
09-25 18:08:13.066 21231-21231/? W/Ads: Could not show rewarded video ad from adapter.
java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.bp ie.a' on a null object reference
at com.google.ads.mediation.AbstractAdViewAdapter.showVideo(:com.google.android.gms.DynamiteModulesA@11509440:228)
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA@11509440:193)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA@11509440:29)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA@11509440:11)
at android.os.Binder.transact(Binder.java:507)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzacz.show(Unknown Source)
at com.google.android.gms.internal.zzadk.show(Unknown Source)
at com.google.unity.ads.RewardBasedVideo$3.run(RewardBasedVideo.java:138)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)
09-25 18:08:13.066 21231-21231/? W/Ads: Could not call showVideo.
android.os.RemoteException
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA@11509440:197)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA@11509440:29)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA@11509440:11)
at android.os.Binder.transact(Binder.java:507)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzacz.show(Unknown Source)
at com.google.android.gms.internal.zzadk.show(Unknown Source)
at com.google.unity.ads.RewardBasedVideo$3.run(RewardBasedVideo.java:138)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6682)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

Is this a known issue? Do you have any suggestion?

Thanks.

support question

Most helpful comment

@rampara It reproducible all time, because I(and other people) use it incorrect.
I thought that it works like Unity Ads: start loading video immediately after show(), when video hasn't finished yet.
But at AdMob we need to load video ON CLOSE VIDEO EVENT(or after it), but I haven't seen something about this in the documentation.

The second thing: after the first video was shown, IsLoaded still returning true value, even if second video hasn't been requested yet and it confused me(not just me, other people confused as well).

At the "HelloWorld" sample you use a button for load the video, and so the situation won't reproduce in this case(because I can tap the button only after video shown and closed) but it isn't usable for real application.

Make the documentation more plain, please.

All 15 comments

@edscodeblenders this is not a known issue. Is it consistently reproducible for you? Do you have any mediation configured for ad placement you are requesting rewarded videos from? On the second ad request do you ever receive the OnAdLoaded ad event? Is this issue reproducible with the HelloWorld sample app from this repo? What version of Google Mobile Ads SDK are you building your app with?

We can reproduce it every single time. The game is live in Google Play if you want to give it a try:
https://play.google.com/store/apps/details?id=com.codeblenders.games.puzzle.hexa.make64

We don't have any mediation configured, just Admob. Our ad-unit-id is the following:
ca-app-pub-9637283630402775/2174153036

We're not handling the OnAdLoaded event, so we're not sure if it's being fired or not. But we check the IsLoaded method and it returns true...

We're using version 3.6.3 as we didn't manage to upgrade to version 3.7.0 yet. I will try to do it and try to reproduce the issue on 3.7.0.

@edscodeblenders having trouble reproducing this issue on my end. Can you provide the version of the Google Play services AARs in the Assets/Plugins/Android directory of your Unity project? Also, the version of Google Play services on the device you're able to reproduce this behavior with.

Experiencing the same problem. The crash log attached:

Could not show rewarded video ad from adapter.
java.lang.NullPointerException: Attempt to read from field 'com.google.android.gms.ads.internal.client.bp ie.a' on a null object reference
at com.google.ads.mediation.AbstractAdViewAdapter.showVideo(:com.google.android.gms.DynamiteModulesA@11509448:228)
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA@11509448:193)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA@11509448:29)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA@11509448:11)
at android.os.Binder.transact(Binder.java:507)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzada.show(Unknown Source)
at com.google.android.gms.internal.zzadl.show(Unknown Source)
at com.google.unity.ads.RewardBasedVideo$3.run(RewardBasedVideo.java:138)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6646)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Could not call showVideo.
android.os.RemoteException
at com.google.android.gms.ads.internal.mediation.client.u.f(:com.google.android.gms.DynamiteModulesA@11509448:197)
at com.google.android.gms.ads.internal.reward.b.a(:com.google.android.gms.DynamiteModulesA@11509448:29)
at com.google.android.gms.ads.internal.reward.client.e.onTransact(:com.google.android.gms.DynamiteModulesA@11509448:11)
at android.os.Binder.transact(Binder.java:507)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzada.show(Unknown Source)
at com.google.android.gms.internal.zzadl.show(Unknown Source)
at com.google.unity.ads.RewardBasedVideo$3.run(RewardBasedVideo.java:138)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6646)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)

@windameister for the crash log you posted, can you provide the version of Google Play services you built the app with (the version of the Play Services AARs in the Assets/Plugins/Android directory of your Unity project) and the version of Google Play Services running on the device where the crash occurred?

@rampara thank you for your response. The playservice aar version I'm using is 11.0.4. I copied below information from my build.gradle.

Btw. The google mobile ads plugin for unity I'm using is 3.6.3. Will try with 3.7.1 and get back to you later.

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile(name: 'GoogleAIDL', ext:'aar')
compile(name: 'GooglePlay', ext:'aar')
compile(name: 'ads-release', ext:'aar')
compile(name: 'animated-vector-drawable-25.3.1', ext:'aar')
compile(name: 'appcompat-v7-25.3.1', ext:'aar')
compile(name: 'cardview-v7-25.3.1', ext:'aar')
compile(name: 'common', ext:'aar')
compile(name: 'customtabs-25.3.1', ext:'aar')
compile(name: 'exoplayer', ext:'aar')
compile(name: 'facebook-4.22.1.0', ext:'aar')
compile(name: 'facebook-android-sdk-4.23.0', ext:'aar')
compile(name: 'facebook-android-wrapper-7.10.0', ext:'aar')
compile(name: 'play-services-ads-11.0.4', ext:'aar')
compile(name: 'play-services-ads-lite-11.0.4', ext:'aar')
compile(name: 'play-services-base-11.0.4', ext:'aar')
compile(name: 'play-services-basement-11.0.4', ext:'aar')
compile(name: 'play-services-clearcut-11.0.4', ext:'aar')
compile(name: 'play-services-gass-11.0.4', ext:'aar')
compile(name: 'play-services-safetynet-11.0.4', ext:'aar')
compile(name: 'play-services-tasks-11.0.4', ext:'aar')
compile(name: 'support-compat-25.3.1', ext:'aar')
compile(name: 'support-core-ui-25.3.1', ext:'aar')
compile(name: 'support-core-utils-25.3.1', ext:'aar')
compile(name: 'support-fragment-25.3.1', ext:'aar')
compile(name: 'support-media-compat-25.3.1', ext:'aar')
compile(name: 'support-v4-25.3.1', ext:'aar')
compile(name: 'support-vector-drawable-25.3.1', ext:'aar')
compile(name: 'unity-ads', ext:'aar')
compile project(':GoogleMobileAdsPlugin')
compile project(':common_lib')
compile project(':localizedappnamelib')
compile project(':native_plugins_lib')
compile project(':voxelbusters_utility_lib')
}

Tried 3.7.1. Not reproducing the Reward Ad problem any more.

However, find a bug in 3.7.1.

Banner ad will show on the top-left of the screen no matter which AdPosition parameter is passed in. (3.7.0 does not have this problem)

I guess it is the new added code: "mPopupWindow.update();" which reset the banner ad's position to the top-left of the screen.

@windameister having trouble reproducing the that behavior. On 3.7.1 I requested a banner to be positioned on the bottom-left and am seeing the following:

screen

Can you open a separate issue for this.

I have the same problem.
The first time it's all going right, but on the second or on the third time there is problem.
I check flag IsLoaded() and if it's true, i call Show method. Here is the code how i use it: https://codeshare.io/5zP3rW

But video doesn't showing.
It's reproducing with Google Mobile Ads Unity Plugin v3.8.0 on Android.

About smartphone: Lenovo s660, android 4.4.2. Haven't tested on other devices yet.

@AndrewVorobey I'm having trouble reproducing this behavior. Is it consistently reproducible for you? Are you able to reproduce it with the HelloWorld sample app from this repo?

@rampara It reproducible all time, because I(and other people) use it incorrect.
I thought that it works like Unity Ads: start loading video immediately after show(), when video hasn't finished yet.
But at AdMob we need to load video ON CLOSE VIDEO EVENT(or after it), but I haven't seen something about this in the documentation.

The second thing: after the first video was shown, IsLoaded still returning true value, even if second video hasn't been requested yet and it confused me(not just me, other people confused as well).

At the "HelloWorld" sample you use a button for load the video, and so the situation won't reproduce in this case(because I can tap the button only after video shown and closed) but it isn't usable for real application.

Make the documentation more plain, please.

@AndrewVorobey the documentation will be updated to reflect that a new ad cannot be loaded until the loaded ad is shown. As for the second issue, IsLoaded() is returning the expected value in my tests. What version of the plugin and Google Play services are you testing with?

The dev docs have been updated with instructions on reloading and ad.

you just need to request loading ad again by using loadRewardedVideoAd() in the last line in the function
Like this :
fun showRewardedVideo(view: View){
If(rewardBasedVideo.isLoaded){
rewardBasedVideo.show()
//Rest of your code}
loadRewardedVideoAd()
}

But at AdMob we need to load video ON CLOSE VIDEO EVENT(or after it), but I haven't seen something about this in the documentation.

I wasted the whole evening trying to figure this one out. Thank you very much, @AndrewVorobey for pointing this out.
Still, even if the documentation was corrected, it makes it look as if requesting a new ad in close event is optional rather than quasi-mandatory as it is now since isLoaded() isn't working properly.

The second thing: after the first video was shown, IsLoaded still returning true value, even if second video hasn't been requested yet and it confused me(not just me, other people confused as well).

This needs to be corrected. One can not simply expect the library/plugin user to request ads only when the current ad isn't being shown. Many of us will simply check at set intervals whether isLoaded() returns true or false in order to request a new ad, whether and ad is currently showing or not... I think it's not reasonable to expect a user to figure out on their own this shouldn't be done.

Was this page helpful?
0 / 5 - 0 ratings