Unity - AdMob ad loading and not showing

4,082 views
Skip to first unread message

Unul Individ

unread,
Jun 15, 2014, 11:29:47 AM6/15/14
to google-adm...@googlegroups.com
    Greetings. I have a pretty odd problem, which after 2 days of searching the whole Internet and also searching this forum, is still bothering me. I thought that maybe here, someone is able to aid me or tell me what I did wrong.
    I have imported the GoogleMobileAds.unitypackage (2.1) from https://github.com/googleads/googleads-mobile-plugins/releases/tag/v2.1 and Unity accepted it without problem, creating the "GoogleMobileAds" and "Plugins" folders in my "Assets" folder. After taking a good look in the ReadMe file, I wrote a simple code which looks like this :

    InterstitialAd reclama = new InterstitialAd("...");
    AdRequest req = new AdRequest.Builder().Build();
    reclama.LoadAd(req);
    if (reclama.IsLoaded())
         reclama.Show();

    Each line is immediately one after another, declaring the interstitial and the request in the same function. I later declared them globally, but it made the app crash on an actual device, while in the Unity editor it had no effect.
    The interstitial is registered at the AdMob site and the ad unit is placed correctly, although I don't think this was necessary.
    I also copied the "google-play-services_lib" folder from the Android SDK installation location into the "Plugins\Android\" folder. The AndroidManifest from the package already came with the INTERNET and ACCESS_NETWORK_STATE permission tags written, but this lib folder brought another AndroidManifest (no file conflict, the original manifest and the folder are in the same directory tree level and the new manifest inside this folder) and I got pretty confused as to which manifest I should use. I couldn't seem to find anything related to the publisher ID though, in both manifests.
    All the action takes place in the "Assets" Unity folder - the scene, resources, etc. When I start the game both in the editor and my device, no ad shows up, even though when, launching in the editor, the console looks like this :

• Created DummyClient
UnityEngine.Debug:Log(Object)
• Dummy CreateIntersitialAd
UnityEngine.Debug:Log(Object)
• Dummy LoadAd
UnityEngine.Debug:Log(Object)
• Dummy IsLoaded
UnityEngine.Debug:Log(Object)
• Dummy ShowInterstitial
UnityEngine.Debug:Log(Object)

    I suppose that I made this right, but as the ads are not showing even when adding ".AddTestDevice()." in the ad request function, I just want to make sure it is done the right way. Do you have any suggestions I might make use of ?

Eric Leichtenschlag

unread,
Jun 15, 2014, 3:32:03 PM6/15/14
to google-adm...@googlegroups.com
Hello,

You will need both manifests (the one provided from the plugin in Assets/Plugins/Android, and the one from google-play-services_lib inside Assets/Plugins/Android/google-play-services_lib. When you build and run your project, Unity will start with the manifest from Assets/Plugins/Android, and automatically merge some stuff from the google-play-services-lib/AndroidManifest.xml that Google Play services requires. The resulting manifest can be found in Temp/StagingArea/AndroidManifest.xml, and that's the manifest Unity will run with.

As for your code, you can't show the interstitial directly after calling LoadAd. The interstitial takes some time to load (say about 2 seconds), so you cannot synchronously show it. So when you're checking reclama.IsLoaded(), it's always false. For that reason, we recommend you do the loading at an earlier point in your app, so it's ready to show when you want to show it.

Thanks,
Eric

Unul Individ

unread,
Jun 15, 2014, 5:21:57 PM6/15/14
to google-adm...@googlegroups.com
Good day sir, thank you kindly for the quick response.
I knew that Ad loading would take time, so I declared the interstitial globally, resulting in an app crash on my tablet. I will try to solve this thing myself, as Ido not really want to waste other people's time on irrelevant things. However I cannot really see why the log says "Dummy ShowInterstitial" even if the ad check returns false. Maybe it has something to do with the fact that the app is not yet published ?
One more small thing bothers me ... the publisher ID, I have it from the AdMob site but I do not really know what do I have to do with it ... from what I suppose I have to put it in the manifest, but I am not sure about which tag to use.
Many thanks for the very fast reply. Have a good day.

Eric Leichtenschlag

unread,
Jun 16, 2014, 10:29:41 AM6/16/14
to google-adm...@googlegroups.com
I don't think you can initialize the interstitial globally. You'll need to do it within some event (maybe awake?).

If you care to know the nitty-gritty on how the plugin works, the plugin can't actually run from within the editor, because it needs to use a native Android or iOS SDK to request ads. If you actually tried to run against the Android or iOS components, you'd see exceptions logged in the editor. So instead we initialize a dummy client if we're running in the editor, and the  dummy client makes mock calls. Since there is no concept of the ad asynchronously loading in the editor, the dummy client always returns true for IsLoaded. That's why you actually get to the ShowInterstitial call in the editor.

If you're using the new AdMob, you'll need to specify your ad unit id (ca-app-pub-xxxxxxxxxxxxxxxx/yyyyyyyyyy) when you initialize your InterstitialAd. You don't need to add it anywhere in the manifest.

Cheers,
Eric

Unul Individ

unread,
Jun 16, 2014, 1:59:31 PM6/16/14
to google-adm...@googlegroups.com
    Thank you very much for the help. I have finally managed to do it. The problem was indeed this global initialization. I apologize for having to waste your time on this annoyance I should've solved myself ...
    I also finally found the answer about the publisher ID (useful for other new developers to AdMob like me) : according to support.andromo.com/kb/monetization-options/setting-up-admob-ads - "Getting an Existing App's Ad Unit ID" section, the pub ID has been replaced by the ad unit ID in the new AdMob; I haven't used the legacy one so I had to figure out a few things.

    Thank you for your help Mr Eric
    Wishing you the best,
    Cristian

Владимир Новак

unread,
Jul 30, 2016, 2:37:17 PM7/30/16
to Google Mobile Ads SDK Developers
I have the same problem exactly where you need to insert in the manifest ID? Help is very necessary !!!!
Untitled-1.jpg

Eric Leichtenschlag (Mobile Ads SDK Team)

unread,
Aug 4, 2016, 7:32:42 PM8/4/16
to Google Mobile Ads SDK Developers
Hello,

This thread is over 2 years old and the Unity plugin has changed a lot since then, including less steps to getting started. Please see https://firebase.google.com/docs/admob/android/games#unity for details, and if you're still having problems, please start a new thread that explains your issue in more detail.

Thanks,
Eric
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages