Reward ads not triggering OnAdRewarded on Android

1,113 views
Skip to first unread message

Alan Ianson

unread,
Jul 7, 2016, 4:40:33 AM7/7/16
to Google Mobile Ads SDK Developers
Hi,

I've set up Ad Mediation on my game and all works great on iOS, but when I run the build on Android, the ads display from AdColony, but I don't get the reward trigger. I can see the other methods firing, saying the ad is opened and closed etc, but no reward.

I've attached a screenshot of my project structure, and also, here added some code snippets of my AdManager class that deals with video.

    void Start()
    {
        _rewardBasedVideo = RewardBasedVideoAd.Instance;

        // RewardBasedVideoAd is a singleton, so handlers should only be registered once.
        _rewardBasedVideo.OnAdRewarded += videoAdComplete;
        _rewardBasedVideo.OnAdLoaded += delegate (object sender, EventArgs args)
        {
            Debug.Log("Video Ad Loaded");
        };

        _rewardBasedVideo.OnAdOpening += delegate (object sender, EventArgs args)
        {
            Debug.Log("Video Ad Opening");
        };

        _rewardBasedVideo.OnAdStarted += delegate (object sender, EventArgs args)
        {
            Debug.Log("Video Ad Started");
        };

        _rewardBasedVideo.OnAdFailedToLoad += delegate (object sender, AdFailedToLoadEventArgs args)
        {
            Debug.Log("Video Ad Failed: " + args.Message);
        };
    }

         public void RequestAndShowVideoAd(int coinReward)
    {
        AdManager.Instance._coinReward = coinReward;    
        AdManager.Instance.RequestVideo();
        AdManager.Instance.StartCoroutine(Instance.ShowVideoLoop());
    }

    private void RequestVideo()
    {
#if UNITY_EDITOR
        string adUnitId = "unused";
#elif UNITY_ANDROID
        string adUnitId = "ca-app-pub-xxx";
#elif UNITY_IOS
        string adUnitId = "ca-app-pub-xxx";
#endif
        _rewardBasedVideo.LoadAd(createAdRequest(), adUnitId);
    }
    private IEnumerator ShowVideoLoop()
    {
        while(!_rewardBasedVideo.IsLoaded())
        {
            yield return new WaitForSeconds(0.5f);
        }
        
        ShowVideo();
    }
    
    private void ShowVideo()
    {
        _rewardBasedVideo.Show();
    }
    
    private void videoAdComplete(object sender, Reward reward)
    {
        // Do Reward
    }



Thanks

Alan Ianson

unread,
Jul 7, 2016, 4:42:45 AM7/7/16
to Google Mobile Ads SDK Developers

Missed the screenshot


Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 7, 2016, 2:39:29 PM7/7/16
to Google Mobile Ads SDK Developers
Hi Alan,

It look like the Mediation Adaptor and SDK files are not in the proper path. If it is a JAR file, it must go into Assets > Plugins > Android > GoogleMobileAdsPlugin > libs folder. And it is an AAR file or a project, then in the Assets > Plugins > Android folder. In any case, here is a sample app that you use to test your Ad Unit ID. Apart from the SDKs and the Adaptors, you also must update the Android Manifest of our plugin file to add the required Activities for the network but only in case you have a JAR file for the SDK. You can go through our Mediation guidelines for each network.

Let us know if you need anything else.

Thanks,
Veer Busani
Mobile Ads SDK Team

Alan Ianson

unread,
Jul 9, 2016, 2:32:44 PM7/9/16
to Google Mobile Ads SDK Developers
Thanks for getting back to me. I tried moving the items into the libs folder, as per the sample app, but when I try to build it, it says the chartboost adapters has already been added. I've searched everywhere in my app, and they're definitely only in that folder, the normal Chartboost jar and the adapter.

Thanks,

Alan

Alan Ianson

unread,
Jul 9, 2016, 3:06:03 PM7/9/16
to Google Mobile Ads SDK Developers
Just tried removing all the mediators, which allows the game to run, but I get an error on launch saying 'class not found: com.google.unity.ads.unityinterstitialadlistener

Alan Ianson

unread,
Jul 9, 2016, 3:07:13 PM7/9/16
to Google Mobile Ads SDK Developers
just to clarify, I only use mediation for reward ads, the rest just use admob

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Jul 11, 2016, 8:56:11 AM7/11/16
to Google Mobile Ads SDK Developers
Hi Alan,

I would assume that you have directly imported the Mediation SDK somewhere in your app. If you look at the sample app that I have provided, even in case of Reward Interstitials, which only serves ads through mediation, I have never imported any SDK, directly into a class, other than AdMob's. All you need to do is copy the Mediation Adaptor and their SDK JAR files into the libs folder and you do not need to import any other SDK's header files. 

For this error - class not found: com.google.unity.ads.unityinterstitialadlistener', would you mind looking this UnityAd only example? This might be able to help you! 

Thanks,
Veer Busani
Mobile Ads SDK Team

Alan Ianson

unread,
Aug 3, 2016, 6:07:50 PM8/3/16
to Google Mobile Ads SDK Developers
I have tried your test app and it works. So my next step was to move the code over and I found that the calls where happening but it seems that the call back is being done in a different thread, and so the code I was using to give the reward wasn't working. I managed to track it down as the sound effects were throwing an exception (causing the rest of the code to stop) which said:

SoundChannelStopList::~SoundChannelStopList() may only be called from main thread!

I tried removing my sound code, and it worked then.

Is there a reason this handler is called from a different thread on Android? How should I be giving my reward? Currently, I'm doing this:

public void HandleRewardBasedVideoClosed(object sender, EventArgs args)
    {
        print("HandleRewardBasedVideoClosed event received");

        if(_rewarded)
        {
            UserProfile.IncreaseFunds("coins", _coinReward);
            MenuManager.Instance.ClosePopup(); 
            _rewarded = false;
        }
    }

    public void HandleRewardBasedVideoRewarded(object sender, Reward args)
    {
        string type = args.Type;
        double amount = args.Amount;
        print("HandleRewardBasedVideoRewarded event received for " + amount.ToString() + " " +
                type);

        _rewarded = true;
    }


I've tried swapping it to HandleRewardBasedVideoRewarded, but get the same issue.

Thanks,

Alan

Alan Ianson

unread,
Aug 3, 2016, 6:10:25 PM8/3/16
to Google Mobile Ads SDK Developers
Sorry, I say it worked when I removed my sound code, but my UI code doesn't execute. The code there that increasesfunds uses a Coroutine to increase the funds, and so works - the app hangs after it though and not interactable, because of another exception that happens when closing popup.

Thanks,

Alan

Alan Ianson

unread,
Aug 3, 2016, 6:44:02 PM8/3/16
to Google Mobile Ads SDK Developers
Right, I've managed to fix it after stumbling across this blog: http://googleadsdeveloper.blogspot.co.uk/2016/04/handling-android-ad-events-in-unity.html

It should really be documented somewhere on how to actually do the rewarding for these videos if the event it on another thread. I've moved my rewarding code into the update loop and checking a flag and its working now.

Veer Arjun Busani(Mobile Ads SDK Team)

unread,
Aug 4, 2016, 9:43:06 AM8/4/16
to Google Mobile Ads SDK Developers
Hi Alan,

Thank you for bringing this up in the forum. Apart from our documentation and forums, the ads developer blog is good place to get more information and updates about our products.


Thanks,
Veer Busani
Mobile Ads SDK Team

fanro...@gmail.com

unread,
Dec 7, 2017, 1:45:20 AM12/7/17
to Google Mobile Ads SDK Developers
this problem occurs in our project too, thanks the work you have done

在 2016年8月4日星期四 UTC+8上午6:44:02,Alan Ianson写道:
Reply all
Reply to author
Forward
0 new messages