ADMob How too, A FULL EXAMPLE

got this error on line 119 of your code in AdController.cs:

‘ListeningReward’ does not implement interface member ‘IRewardedVideoAdListener.OnRewardedVideoCompleted()’

Dont know what to do.

Add a new method:

    public void OnRewardedVideoCompleted()
    {
        //ad completed
    }

Thanks for this! It is just what I was looking for and works like a charm.

Has anyone got BANNER ads to work?

Does anyone have an example of this working with the latest Monogame (3.8)?

I can not make current version work with the example.

I’m having issues with 3.8 too, are you also seeing this error?

Java.Lang.RuntimeException: 'Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

Managed to fix my error by including metadata in the Manifest, ads are now displaying normally in the game.

Is there a way to have mediation with other ad providers such as MoPub?

Full question here: https://community.monogame.net/t/mopub-ads-mediation-with-admob/

Hi All,

I got it working fine on the Android side. Works well.
On the IOS side I am stumped at a more basic level (see below)
I seem to have a linking or reference problem. Is there a simple step or solution I am missing. I am hoping can tell me the step I have screwed or missed.

thanks,

Severity Code Description Project File Line Suppression State
Error Native linking failed, undefined symbol: _NSValueFromGADAdSize. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._GetNSValue. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _NSStringFromGADAdSize. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._GetNSString. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADSimulatorID. This symbol was referenced by the managed member Google.MobileAds.Request.SimulatorId. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADErrorDomain. This symbol was referenced by the managed member Google.MobileAds.RequestError._ErrorDomain. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeSmartBannerPortrait. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._SmartBannerPortrait. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeSmartBannerLandscape. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._SmartBannerLandscape. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeSkyscraper. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._Skyscraper. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeMediumRectangle. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._MediumRectangle. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeLeaderboard. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._Leaderboard. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeLargeBanner. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._LargeBanner. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeInvalid. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._Invalid. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeFullBanner. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._FullBanner. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeFluid. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._Fluid. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdSizeBanner. This symbol was referenced by the managed member Google.MobileAds.AdSizeCons._Banner. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdLoaderAdTypeUnifiedNative. This symbol was referenced by the managed member Google.MobileAds.AdLoaderAdTypeExtensions.kGADAdLoaderAdTypeUnifiedNative. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711
Error Native linking failed, undefined symbol: _kGADAdLoaderAdTypeNativeCustomTemplate. This symbol was referenced by the managed member Google.MobileAds.AdLoaderAdTypeExtensions.kGADAdLoaderAdTypeNativeCustomTemplate. Please verify that all the necessary frameworks have been referenced and native libraries linked. MM.iOS C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets 711

I have these to errors:

Severity Code Description Project File Line Suppression State
Warning The referenced component ‘C:\Users\admin\AppData\Local\XamarinBuildDownloadCache\FAdM-7.53.1\Frameworks\GoogleMobileAdsFramework-Current\GoogleMobileAds.framework’ could not be found. AdMobBuddy.iOS
Warning The referenced component ‘C:\Users\admin\AppData\Local\XamarinBuildDownloadCache\GAppM-6.2.1\Frameworks\GoogleAppMeasurement.framework’ could not be found. AdMobBuddy.iOS

Just in case anybody is still looking for banner ads I extended this sample. I removed the code related to reward ads because it is all deprecated now. Hope it helps somebody.

In order to display banner adds we need to use a FrameLayout to render MonoGame in instead of a View. The code to initialize banner ads requires a FrameLayout parameter. It constructs the banner ad view, adds it to a LinearLayout and adds that to the frame layout.

using System;
using AdMobDemo;
using Android.Gms.Ads;
using Android.Views;
using Android.Widget;

namespace AdController
{
    public static class AdController
    {
        public static InterstitialAd interstitialHandle = null;
        public static AdView AdView = null;

        public static event EventHandler AdClosed;

        // AD ID's This is a test use yours from Admob
        public static string adID1 = "ca-app-pub-3940256099942544/1033173712"; // standard full page ad
        public static string adID3 = "ca-app-pub-3940256099942544/6300978111"; // banner ad

        public static bool adRegularLoaded = false;
        public static bool adBannerLoaded = false;

        public static void InitBannerAd(FrameLayout fl)
        {
            LinearLayout ll = new LinearLayout((Activity1)Game1.Activity)
            {
                Orientation = Orientation.Horizontal
            };

            ll.SetGravity(GravityFlags.CenterHorizontal | GravityFlags.Bottom);

            MobileAds.Initialize(Game1.Activity);

            AdView = new AdView((Activity1)Game1.Activity)
            {
                AdUnitId = adID3,
                AdSize = AdSize.Banner
            };

            ListeningBanner listening = new ListeningBanner();
            
            AdView.AdListener = listening;
            AdView.LoadAd(new AdRequest.Builder().Build());
            AdView.Visibility = ViewStates.Visible;

            ll.AddView(AdView);
            fl.AddView(ll);
        }

        public static void InitRegularAd()
        {
            MobileAds.Initialize(Game1.Activity);
            interstitialHandle = new InterstitialAd((Activity1)Game1.Activity)
            {
                AdUnitId = adID1,
                AdListener = null
            };

            ListeningRegular listening = new ListeningRegular();

            interstitialHandle.AdListener = listening;
            interstitialHandle.LoadAd(new AdRequest.Builder().Build());

            listening.AdClosed += Listening_AdClosed;
        }

        private static void Listening_AdClosed(object sender, EventArgs e)
        {
            AdClosed?.Invoke(null, null);
        }

        public static void ShowRegularAd()
        {
            if (adRegularLoaded)
            {
                adRegularLoaded = false;
                interstitialHandle.Show();
            }
        }
    }

    internal class ListeningRegular : AdListener
    {
        public event EventHandler AdClosed;

        public override void OnAdLoaded()
        {
            AdController.adRegularLoaded = true;
            base.OnAdLoaded();
        }

        public override void OnAdClosed()
        {
            AdController.interstitialHandle.LoadAd(new AdRequest.Builder().Build());
            AdClosed?.Invoke(this, null);
            base.OnAdClosed();
        }
        public override void OnAdOpened()
        {
            base.OnAdOpened();
        }
    }

    internal class ListeningBanner : AdListener
    {
        public override void OnAdFailedToLoad(LoadAdError p0)
        {
            base.OnAdFailedToLoad(p0);
        }

        public override void OnAdLoaded()
        {
            AdController.adBannerLoaded = true;
            base.OnAdLoaded();
        }

        public override void OnAdClosed()
        {
            AdController.AdView.LoadAd(new AdRequest.Builder().Build());
            base.OnAdClosed();
        }
    }
}

Calling the initialization is done in Activity1.cs. Instead of hosting MonoGame in a View it is hosted in a FrameLayout as I mentioned earlier. You call the initialize method for banner ads in the AdController here. Banner ads are set to automatically repopulate if they are tapped.

using AdController;
using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using Android.Widget;
using Microsoft.Xna.Framework;

namespace AdMobDemo
{
    [Activity(
        Label = "@string/app_name",
        MainLauncher = true,
        Icon = "@drawable/icon",
        AlwaysRetainTaskState = true,
        LaunchMode = LaunchMode.SingleInstance,
        ScreenOrientation = ScreenOrientation.FullUser,
        ConfigurationChanges = ConfigChanges.Orientation | ConfigChanges.Keyboard | ConfigChanges.KeyboardHidden | ConfigChanges.ScreenSize
    )]
    public class Activity1 : AndroidGameActivity
    {
        private Game1 _game;
        private FrameLayout fl;

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            _game = new Game1();

            fl = new FrameLayout(this);
            fl.AddView((View)_game.Services.GetService(typeof(View)));

            AdController.InitBannerAd(fl);

            SetContentView(fl);

            _game.Run();
        }
    }
}

In some instance I am fine with just adding Xamarin.GooglePlayServices.Ads.Lite for NuGet packages but other times I need to add the dependencies. Here is a list of packages that I sometimes need to add to get banner ads to work.

  • Xamarin.AndroidX.Browser
  • Xamarin.AndroidX.Collection
  • Xamarin.AndroidX.Core
  • Xamarin.AndroidX.Legacy.Support.V4
  • Xamarin.Build.Download
  • Xamarin.GooglePlayServices.Ads
  • Xamarin.GooglePlayServices.Ads.Base
  • Xamarin.GooglePlayServices.Ads.Identifier
  • Xamarin.GooglePlayServices.Ads.Lite
  • Xamarin.GooglePlayServices.Basement
  • Xamarin.GooglePlayServices.Gass

Adding Xamarin.Build.Download will give you a deprecated warning. It also says that you can ignore it if your project builds fine.

4 Likes

at least more than two days is required to ads be displayed

why reward ad is deprecated ? the ad type is still in google Admob website

Google refactored the entire AdMob codebase. Rewarded ads are still available, but all the classes have been renamed and the functionality has been reorganized. Even worse, Xamarin hasn’t kept up with the changed correctly and their AdMob wrappers are full of errors and are unusable. The only way I’ve been able to get AdMob to work is to use an older version of Xamarin.GooglePlayServices.Ads.Lite 119.7.0

1 Like

this sample is not working in latest monogame ,there are lot’s of changes in interfaces and class names ,any idea how to make rewarded Ad to work?

Hello,
Thanks for the adjustment
I found a library that works with xamarin android and ios admob (interstitial, rewards…). https://github.com/marcojak/MTAdmob
on the other hand I can not integrate it on monogame
Can you help me ?

Thank you

The Xamarin wrapper around Xamarin.GooglePlayServices.Ads.Lite is still broken, but there is a workaround documented in this thread:

I was able to get AdMob working using that bit of code :+1:

2 Likes

thank you i will try this does it work with ios?

Hello,

I found a solution that works well
reward interstitial banner…

the problem is that it only runs on xamarinForms

this is the one I site before https://github.com/marcojak/MTAdmob
is anyone willing to help me develop a solution that integrates this work into monogaming?
I don’t know how one can call views in monogame or call monogame in xamarin forms

thank you

Hi, does anyone have a working full example for the current version of AdMob and Monogame?
I’m having trouble inserting a banner.