(AdMob/C++) Advertisements are not showing

I am using Cocos2D-X 3.13.1 (Linux) and the SDKBOX AdMob integration (installed via sdkbox import admob).

In my class, I have the following code (MainMenuScene inherits cocos2d::LayerColor):

bool MainMenuScene::init() {
    if(!Layer::init()) {
        return false;
    }

    if(!LayerColor::initWithColor(Color4B(255, 255, 255, 255))) {
        return false;
    }

#ifdef SDKBOX_ENABLED
    CCLOG("CCLog: (Ads) Caching mainmenu.");
    sdkbox::PluginAdMob::cache("mainmenu");
    CCLOG("CCLog: (Ads) Showing mainmenu.");
    sdkbox::PluginAdMob::show("mainmenu");
#else
    CCLOG("CCLog: (Ads) Not enabled.");
#endif

...

However, the banner advertisements (my only ad type) are not displaying at all.

Logcat reveals the following:

11-07 22:04:09.285 27743 27743 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-07 22:04:09.363 27743 27770 D cocos2d-x debug info: CCLog: (Ads) Caching mainmenu.
11-07 22:04:09.363 27743 27770 D cocos2d-x debug info: CCLog: (Ads) Showing mainmenu.
11-07 22:04:09.585 27743 27743 I Ads     : Starting ad request.
11-07 22:04:09.587 27743 27743 I Ads     : Use AdRequest.Builder.addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") to get test ads on this device.
11-07 22:04:09.626 27743 27743 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-07 22:04:09.628 27743 27743 I Ads     : Starting ad request.
11-07 22:04:09.628 27743 27743 I Ads     : Use AdRequest.Builder.addTestDevice("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX") to get test ads on this device.
11-07 22:04:09.632 27743 27823 D hg      :      at com.google.android.gms.ads.internal.y.a(:com.google.android.gms.DynamiteModulesA:3106)
11-07 22:04:09.632 27743 27823 D hg      :      at com.google.android.gms.ads.internal.request.c.a(:com.google.android.gms.DynamiteModulesA:144)
11-07 22:04:09.632 27743 27823 D hg      :      at com.google.android.gms.ads.internal.util.b.run(:com.google.android.gms.DynamiteModulesA:19)
11-07 22:04:09.632 27743 27823 D hg      :      at com.google.android.gms.ads.internal.util.y.call(:com.google.android.gms.DynamiteModulesA:1055)
11-07 22:04:09.632 27743 27823 D hg      :      at com.google.android.gms.ads.internal.util.z.run(:com.google.android.gms.DynamiteModulesA:75)
11-07 22:04:12.057 27743 27743 I Ads     : Scheduling ad refresh 30000 milliseconds from now.
11-07 22:04:12.092 27743 27743 I Ads     : Ad finished loading.
11-07 22:04:12.146 27743 27743 I chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-07 22:04:12.146 27743 27743 I chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-07 22:04:12.367 27743 27743 I chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-07 22:04:42.067 27743 27743 I Ads     : Ad is not visible. Not refreshing ad.
11-07 22:04:42.067 27743 27743 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-07 22:05:09.610 27743 27743 W Ads     : Timed out waiting for ad response.
11-07 22:05:09.610 27743 27743 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-07 22:05:09.610 27743 27743 W Ads     : Failed to load ad: 2
11-07 22:05:42.068 27743 27743 I Ads     : Ad is not visible. Not refreshing ad.
11-07 22:05:42.068 27743 27743 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-07 22:06:09.610 27743 27743 I Ads     : Ad is not visible. Not refreshing ad.
11-07 22:06:09.610 27743 27743 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-07 22:06:42.068 27743 27743 I Ads     : Ad is not visible. Not refreshing ad.
11-07 22:06:42.068 27743 27743 I Ads     : Scheduling ad refresh 60000 milliseconds from now.

I noticed Failed to load ad: 2, however the internet (StackOverflow) indicates that this is due to AdMob being unable to connect to the internet. I have internet permissions in my AndroidManifest.xml file, and do not have an adblocker installed. Other apps (that aren’t my creation) work well. There are no SDKBOX errors in the log, either.

I should note, in AdMob app settings, I have scheduled the advertisement to refresh every 30 seconds, even though it only mentions that once in the log (all other times mentioning 60 seconds for some reason).

I have tried looking at the provided sample code, however it seems out of date . Targeting armeabi-4.8, whereas the latest is armeabi-4.9. As 4.8 is hardcoded in the Python scripts, manually changing it to 4.9 works. However, a linking error occurs in libcocos2dxinternal.a complaining about bzero() not being able to be found.

I’m at a loss. Please help. Thank you.

Also posted to: http://www.sdkbox.com/answers/question/admobc-advertisements-are-not-showing/

I take few hours for new id work. For testing, you can set debug to true

It has been over a day since signing up to AdMob and creating these app/advertisement ID’s.

I have also set the "test" key to both true and false to no effect in Resources/sdkbox_config.json.

Based on this error log, you need to turn on test in order to test your device. Can you share the log after you turn on the test mode?

when you caching ads, you have to wait it available before you show it.

Hi nite,

I have tried turning test mode on and off by setting the "test" key to both true and false in Resources/sdkbox_config.json, and it makes no difference.

Yes I am aware, it shouldn’t take many hours though.

Can you post the log with after you turned on the test mode?

Sure, sorry.

11-08 11:36:03.540 13792 13820 D cocos2d-x debug info: CCLog: (Ads) Initialising PluginAdMob
11-08 11:36:03.679 13792 13792 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:36:03.798 13792 13820 D cocos2d-x debug info: CCLog: (Ads) Caching mainmenu.
11-08 11:36:03.798 13792 13820 D cocos2d-x debug info: CCLog: (Ads) Showing mainmenu.
11-08 11:36:03.991 13792 13792 I Ads     : Starting ad request.
11-08 11:36:04.038 13792 13792 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:36:04.040 13792 13792 I Ads     : Starting ad request.
11-08 11:36:04.065 13792 13874 D hg      :      at com.google.android.gms.ads.internal.y.a(:com.google.android.gms.DynamiteModulesA:3106)
11-08 11:36:04.065 13792 13874 D hg      :      at com.google.android.gms.ads.internal.request.c.a(:com.google.android.gms.DynamiteModulesA:144)
11-08 11:36:04.065 13792 13874 D hg      :      at com.google.android.gms.ads.internal.util.b.run(:com.google.android.gms.DynamiteModulesA:19)
11-08 11:36:04.065 13792 13874 D hg      :      at com.google.android.gms.ads.internal.util.y.call(:com.google.android.gms.DynamiteModulesA:1055)
11-08 11:36:04.065 13792 13874 D hg      :      at com.google.android.gms.ads.internal.util.z.run(:com.google.android.gms.DynamiteModulesA:75)
11-08 11:36:04.201  8534 13881 W Ads     : App does not have the required permissions to get location
11-08 11:36:05.181 13792 13792 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:36:05.217 13792 13792 I Ads     : Ad finished loading.
11-08 11:36:05.254 13792 13792 I chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:36:05.255 13792 13792 I chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:36:05.352 13792 13792 I chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:37:04.014 13792 13792 W Ads     : Timed out waiting for ad response.
11-08 11:37:04.016 13792 13792 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:37:04.017 13792 13792 W Ads     : Failed to load ad: 2
11-08 11:37:05.181 13792 13792 I Ads     : Ad is not visible. Not refreshing ad.
11-08 11:37:05.181 13792 13792 I Ads     : Scheduling ad refresh 60000 milliseconds from now.

Are you using banner ads or interstitial ads?

Banner advertisements.

No interstitial ads at all.

Your integration looks correct based on the log files.

If you sure your internet connection is not the problem. Note in certain country, like china you need some kind of proxy in order for ads to load correctly.

Try using the official sample app_id and see if that helps.

I live in Sydney, Australia. And advertisements (AdMob) in other apps works fine.

And I tried the sample advertisement ID, too, to no avail.

Here are my logs:

1-08 11:53:31.399 18275 18315 D cocos2d-x debug info: CCLog: (Ads) Initialising PluginAdMob
11-08 11:53:31.558 18275 18275 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:53:31.912 18275 18275 I Ads     : Starting ad request.
11-08 11:53:31.933 18376 18376 I dex2oat : dex2oat took 157.793ms (threads: 4) arena alloc=73KB java alloc=42KB native alloc=1305KB free=998KB
11-08 11:53:32.093 18275 18315 D cocos2d-x debug info: CCLog: (Ads) Caching mainmenu.
11-08 11:53:32.093 18275 18315 D cocos2d-x debug info: CCLog: (Ads) Showing mainmenu.
11-08 11:53:32.098 18275 18416 D hg      :      at com.google.android.gms.ads.internal.y.a(:com.google.android.gms.DynamiteModulesA:3106)
11-08 11:53:32.098 18275 18416 D hg      :      at com.google.android.gms.ads.internal.request.c.a(:com.google.android.gms.DynamiteModulesA:144)
11-08 11:53:32.098 18275 18416 D hg      :      at com.google.android.gms.ads.internal.util.b.run(:com.google.android.gms.DynamiteModulesA:19)
11-08 11:53:32.098 18275 18416 D hg      :      at com.google.android.gms.ads.internal.util.y.call(:com.google.android.gms.DynamiteModulesA:1055)
11-08 11:53:32.098 18275 18416 D hg      :      at com.google.android.gms.ads.internal.util.z.run(:com.google.android.gms.DynamiteModulesA:75)
11-08 11:53:32.098 18275 18275 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:53:32.100 18275 18275 I Ads     : Starting ad request.
11-08 11:53:32.511  8534  8534 I Ads     : Received log message: <Google:HTML> You are using version 9.5 of the Google Play services Ads SDK. Please consider updating your SDK to the most recent SDK version to get the latest features and bug fixes. See http://goo.gl/r2TRzC for instructions on how to get the latest version of Google Play services.
11-08 11:53:34.138 18275 18275 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:53:34.190 18275 18275 I Ads     : Ad finished loading.
11-08 11:53:34.208 18275 18275 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:53:34.211 18275 18275 I Ads     : Ad finished loading.
11-08 11:53:34.378 18275 18275 I chromium: [INFO:CONSOLE(0)] "Creating Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.378 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.406 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Downloading event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.434 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (0 of 3) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/production/sdk-core-v40-impl.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.449 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (1 of 3) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/native_ads.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.451 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (2 of 3) https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.js", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.598 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Progress event (3 of 3) ", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:34.598 18275 18275 I chromium: [INFO:CONSOLE(0)] "Application Cache Cached event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)

and (after closing and reopening the app):

11-08 11:53:48.214 18730 18757 D cocos2d-x debug info: CCLog: (Ads) Initialising PluginAdMob
11-08 11:53:48.393 18730 18730 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:53:48.445 18730 18757 D cocos2d-x debug info: CCLog: (Ads) Caching mainmenu.
11-08 11:53:48.445 18730 18757 D cocos2d-x debug info: CCLog: (Ads) Showing mainmenu.
11-08 11:53:48.656 18730 18730 I Ads     : Starting ad request.
11-08 11:53:48.696 18730 18730 D DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
11-08 11:53:48.698 18730 18730 I Ads     : Starting ad request.
11-08 11:53:48.748 18730 18810 D hg      :      at com.google.android.gms.ads.internal.y.a(:com.google.android.gms.DynamiteModulesA:3106)
11-08 11:53:48.748 18730 18810 D hg      :      at com.google.android.gms.ads.internal.request.c.a(:com.google.android.gms.DynamiteModulesA:144)
11-08 11:53:48.748 18730 18810 D hg      :      at com.google.android.gms.ads.internal.util.b.run(:com.google.android.gms.DynamiteModulesA:19)
11-08 11:53:48.748 18730 18810 D hg      :      at com.google.android.gms.ads.internal.util.y.call(:com.google.android.gms.DynamiteModulesA:1055)
11-08 11:53:48.748 18730 18810 D hg      :      at com.google.android.gms.ads.internal.util.z.run(:com.google.android.gms.DynamiteModulesA:75)
11-08 11:53:48.853  8534 18820 W Ads     : App does not have the required permissions to get location
11-08 11:53:49.766 18730 18730 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:53:49.804 18730 18730 I Ads     : Ad finished loading.
11-08 11:53:49.843 18730 18730 I chromium: [INFO:CONSOLE(0)] "Document was loaded from Application Cache with manifest https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.appcache", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:49.843 18730 18730 I chromium: [INFO:CONSOLE(0)] "Application Cache Checking event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:53:49.949 18730 18730 I chromium: [INFO:CONSOLE(0)] "Application Cache NoUpdate event", source: https://googleads.g.doubleclick.net/mads/static/mad/sdk/native/sdk-core-v40-loader.html (0)
11-08 11:54:48.674 18730 18730 W Ads     : Timed out waiting for ad response.
11-08 11:54:48.676 18730 18730 I Ads     : Scheduling ad refresh 60000 milliseconds from now.
11-08 11:54:48.676 18730 18730 W Ads     : Failed to load ad: 2
11-08 11:54:49.769 18730 18730 I Ads     : Ad is not visible. Not refreshing ad.
11-08 11:54:49.769 18730 18730 I Ads     : Scheduling ad refresh 60000 milliseconds from now.

based on your app log, seems like you trying to display the ads right away, what if you wait for the adReceived callback? before attempting display ads?

Oh wow!

You’re totally right. I skipped over that part, thinking it was only to do with interstitial ads.

Thank you!

For those in the future facing a similar problem:

In the scene I wanted to show the advertisement, I had the following:

  • Up the top, include the AdMob header file and declare the following class:
#ifdef SDKBOX_ENABLED
#include "pluginadmob/PluginAdMob.h"

class AdEventListener : public sdkbox::AdMobListener {
public:
    virtual void adViewDidReceiveAd(const std::string &name) {
        sdkbox::PluginAdMob::show(name);
    }
};
#endif

USING_NS_CC;
  • Inside the scene initialisation function, have the following (replacing "mainmenu" with the name of your ad declared in Resources/sdkbox_config.json:
bool MainMenuScene::init() {
    if(!Layer::init()) {
        return false;
    }

#ifdef SDKBOX_ENABLED
    sdkbox::PluginAdMob::cache("mainmenu");
    sdkbox::PluginAdMob::setListener(new AdEventListener());
#endif
  • And that should be it! (don’t forget in AppDelegate.cpp to initialise the AdMob plugin)