Admob for Xamarin made easy

Home / Admob for Xamarin made easy

Admob for Xamarin made easy

May 6, 2019 | Guide, Plugin, Tutorial | 110 Comments

In this tutorial I’ll show you how to monetize your Xamarin apps with AdMob using my MTAdmob plugin.

Important: If you receive errors compiling the code for iOS, install the package Xamarin.Google.iOS.MobileAds in your iOS project.

UPDATE 16/10/2019: MTAdmob is now Open Source on Github: https://github.com/marcojak/MTAdmobUPDATE 11/10/2019: VERY IMPORTANT!!! The new version 1.4.4 is out. There is an issue in the latest Xamarin.Google.iOS.MobileAds 7.47. Because of this, in your iOS project you have to install the plugin Xamarin.Google.iOS.SignIn 4.4.0 too. This will let you compile and use MobileAds.

UPDATE 1/May/2019: I’ve released the new version 1.3 thas sovles some issues with iOS and improves performances.

UPDATE: From version 1.2, MTAdmob supports also Google ads rewarded videos for Android and iOS

UPDATE: I’ve added on github the source code of a project to test this Admob plugin. You can find it here: https://github.com/marcojak/TestMTAdmob

To help you to speed up your Xamarin development, I’ve created a set of plugins, one of them is MTAdmob. Thanks to this plugin you can add Admob banners and Insterstitials in just few lines of code. It couldn’t be easier than that and I’ll show you.

Install the plugin

First of all, right click on your Xamarin solution and select “Manage Nuget packages for Solution”

manage nuget

Visual Studio will open a new screen where you can search and install one or more nuget packages. In this case we can search for the MTAdmob plugin. Searching for MarcTron will show you all my packages (I’m sure you can find other useful plugins that I’ve written), and we can select the MTAdmob plugin as showed in the next image.

It’s very important that you install the plugin in your PCL/.Net standard project and in your platform projects (Android, iOS, UWP).

After the Admob plugin is installed we can add banners and insterstitials to our projects.

Add Ads to our project

With version 1.0 the MTAdmob plugin supports banner and interstitials for Android and iOS. If you would like to see the plugin supporting also the UWP platform, let me now and I’ll add the support in a new version.

As I’ve said we can add Banners and Interstitials Admob ads to our project. Let’s start with the Banners

How to add an Admob Banner

An Admob banner is just a view inside our page. It means that we can add it using XAML or C#. First of all let’s see how to add an Admob banner using XAML.

Add an Admob Banner with XAML

In MTAdmob to use an Admob banner I’ve created a custom control called AdView, so to use it we can use this code:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:controls="clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob"
             x:Class="Test.MTAdmob.MainPage">

<StackLayout>
    <Label Text="Let's test an Admob Banner!" 
           HorizontalOptions="Center"
           VerticalOptions="CenterAndExpand" />
    <!-- Place the Admob controls here -->
    <controls:MTAdView/>
</StackLayout>

In this example we have created a StackLayout with 2 controls: a label and an AdView (our Admob banner). Easy! Isn’t it???

The AdView control is basically a View so you can use all the properties you can think of like: HorizontalOptions, VerticalOptions, IsVisible…

In addition to these properties, I’ve added in AdView two other properties: AdsId and PersonalizedAds.

AdsId: Allows you to add the Banner Id (you can find it in your Admob account)

PersonalizedAds: This allow you to use non personalized ads. For example in case of GPDR. Of course it’s better to use personalized Ads.

To use these properties you can update the previous code to:

<controls:AdView PersonalizedAds="true" AdsId="xxxxxxxxxxxxxxxxxx"/>

Add an Admob Banner with C#

In case you don’t write your pages with XAML or you write your UI in C# or you want to add your view only in some cases, you can add your Admob Banner using this code:

using MarcTron.Plugin;
...
MTAdView ads = new MTAdView();

Of course you need to attach this View to your layout, but you know how to do it (If not, feel free to ask).

To use the custom properties you can change the previous code to:

...
MTAdView ads = new MTAdView();
ads.AdsId = "xxx";
ads.PersonalizedAds = true;

Also in this case, to add an Admob banner is INCREDIBILY EASY!!!

Global Custom Properties

As you have seen, the properties AdsId and PersonalizedAds belong to a single AdView. It means that you have to set them for every Admob Banner.

To make things even easier I’ve added the option to set these properties only once. To do so, you can use this C# code:

CrossMTAdmob.Current.UserPersonalizedAds = true;
CrossMTAdmob.Current.AdsId = "xxxxxxxxxxxxxxxx";

In this case all your Admob banner will show personalized ads and will have the same Id.

If you set local and global properties, the local ones will have higher priority.

Use of Banner Events

I’ve added 4 events to the Admob banner that you could find nice to have. These events are:

  • AdsClicked When a user clicks on the ads
  • AdsClosed When the user closes the ads
  • AdsImpression Called when an impression is recorded for an ad.
  • AdsOpened When the ads is opened

To use these events you can write this code:

AdView myAds = new AdView();
myAds.AdsClicked += MyAdsAdsClicked;
myAds.AdsClosed += MyAds_AdVClosed;
myAds.AdsImpression += MyAds_AdVImpression;
myAds.AdsOpened += MyAds_AdVOpened;

Of course you can use these events also if you have declared your AdView in your XAML code.

Admob Interstitials

Now that we know how to add Admob banners using my plugin MTAdmob, let’s see how we can add Admob Interstitials. If possible, to add an Admob interstitial is even easier. You just need a single line of code. Don’t you believe me? Look here how to show an Admob interstitial:

CrossMTAdmob.Current.ShowInterstitial("ca-app-pub-xxxxxxxxxxxxxxxx/xxxxxxxxxx");

I told you!!! That’s it!!! With that line of code you have just showed an Interstitial in you app. Of course you need to replace that string with the Insterstitial ID you can find in your Admob account.

Events for Interstitials

There 3 events that you can use with Interstitials:

OnInterstitialLoaded        When it's loaded
OnInterstitialOpened        When it's opened      
OnInterstitialClosed        When it's closed

Rewarded Video

From version 1.1 the plugin supports the amazing Rewarded Video too.

To show a rewarded video you just need a single line of code:

CrossMTAdmob.Current.ShowRewardedVideo("xx-xxx-xxx-xxxxxxxxxxxxxxxxx/xxxxxxxxxx");

Events for Rewarded videos

There are 7 events that you can use with the Rewarded video Ads:

OnRewarded                          When the user gets a reward
OnRewardedVideoAdClosed             When the ads is closed
OnRewardedVideoAdFailedToLoad       When the ads fails to load
OnRewardedVideoAdLeftApplication    When the users leaves the application
OnRewardedVideoAdLoaded             When the ads is loaded
OnRewardedVideoAdOpened             When the ads is opened
OnRewardedVideoStarted              When the ads starts

Initialization

Before you can use the Admob banners and Interstitials, you need to initialize it. You need to do it only once so it makes sense to initialize it onside the OnCreate method in Android and FinishedLaunching in iOS.

In your Android project add this line in your OnCreate method:

MobileAds.Initialize(ApplicationContext, "ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx");

In your iOS project add this line in your FinishedLaunching method:

MobileAds.SharedInstance.Start(CompletionHandler);

private void CompletionHandler(InitializationStatus status){}

In iOS you should install the package Xamarin.Google.iOS.MobileAds and Xamarin.Google.iOS.SignIn!

You need to add to your Info.plist file this:

	<key>GADApplicationIdentifier</key>
	<string>YOUR APP ID</string>
	<key>GADIsAdManagerApp</key>
	<true/>

Android Project (Important)

In your AndroidManifest you should add these lines:

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application android:label="Test.MTAdmob.Android">
    <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version"/>
    <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
    <activity android:name="com.google.android.gms.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" android:theme="@android:style/Theme.Translucent" />
</application>

iOS Project (Important)

From version 1.4.4 you need to manually install the packages: Xamarin.Google.iOS.MobileAds and Xamarin.Google.iOS.SignIn! If you don’t install them, your app will not compile.

Some useful links

Conclusion

This Admob MTAdmob plugin is incredibly easy to use but in case you need help, or you want to suggest a new feature or for any other reason, write me.

, , , , , , , ,

About Author

about author

Marco Troncone

.Net Developer
Xamarin Lover

110 Comments
  1. Eddy

    Hello,
    good jobs.
    How get event for interstitial and reward ads ?

    • Marco Troncone

      In this moment I’ve added only events for banners. I’ll try tomorrow to update the nuget package to add events also for interstitials.

      Are there any events/features you would like to see there?

      Marco

  2. Eddy Boughioul

    Hello,
    It can be interesting to have onRewardedVideoCompleted() and onAdClosed() for reward and interstitial
    TY

  3. Add Admob Rewarded video Ads to Android and iOS | Xamarin eXpert

    A detailed tutorial on how to use the plugin:
    https://www.xamarinexpert.it/blog/add-admob-rewarded-video-ads-to-android-and-ios-with-a-single-line-of-code/

  4. J0hs

    First of all thanks a lot for your plugins. This plugin and the SQL one has helped me a great deal.

    The interstitial works fine, but the banner ad gives me an error.

    System.TypeInitializationException: The type initializer for ‘MarcTron.Plugin.Controls.AdView’ threw an exception.

    • Marco Troncone

      Hi J0hs,
      Thanks for your comment.

      Can you give me more info about the error?
      What version of the plugin are you using? What version of Xamarin.Forms?
      On which platform do you get the error?

      The more information I get, the better I can help you.
      If you have also code that you thing makes sense to share,
      you can add an issue here:
      https://bitbucket.org/marcojak81/mtadmob/issues

      Thank you

      • J0hs

        I used my own implementation for the banner instead, and now it is working as intended. For the interstitial, I am still using the plugin.

        • Marco Troncone

          That’s good!

          But I’m sorry the banner didn’t work for you.
          What version of Xamarin.Forms are you using?

  5. Zoli

    REally nice PLugin, but unfortunately it’s not ok for Interstitials. As the load + show is in one function. The problem is, when you call it, the load takes 1-5 seconds (in the background), then show() is called. This makes it useless, as you cannot block your app for 5 seconds before displaying the Ad. Suggestion: in the constructor, already call load() for the app, and the current ShowInterstitial() should just call show(), which should be already loaded. Right after the .show(), you should re-load the next ad (still in the ShowInterstitial() ).
    Or, just make these functions public, and let the users call those.

    • Marco Troncone

      Hi Zoli,

      Thank you,
      This is a very good suggestion.
      I’ll try to change it during the weekend so that I can release soon a new version with the changes suggested.

    • Marco Troncone

      Hi Zoli,

      I’ve published the new version 1.2 of the MTAdmob plugin.

      Now there are 2 methods to Load and Show the plugin so you have total control over the interstitials and rewarded videos.
      For example to load an interstitial the method is “LoadInterstitial”. To show it is “ShowInterstitial”.
      There are also new methods to check if an interstitial or rewarded video are loaded.

  6. PILOT

    thank you so much marco. this is what I’m looking. ı trıed many times but ıt doesn’t work ın my project.

    I used that for Rewarded Videos but I got error lıke that {System.NotImplementedException: This functionality is not implemented in the portable version of this assembly.}

    • Marco Troncone

      You should install the library in every project, so your .NetStandard project AND your Android and iOS projects.
      If you install it only in your .NetStandard project, it will not work.

  7. ahmet

    hi mr. marco
    ı havent found out what ı am missıng but ı made all wrıttens step by step but when ı make archıve and transfer apk fıle to andorıd phone ı cant see my banner ads (google admob – Not testıng values)

    • Marco Troncone

      Hi Ahmet,

      Does it work in test mode?
      If it works in test mode, then it’s possible that Google still has to authenticate your account so you’ll need to wait few hours (I think up to 24 to receive actual ads).

      If it doesn’t work in test mode, have you tried to rotate the phone to see if you see the banner? sometimes you don’t have enough vertical space to show the ads. In that case you should set “HeightRequest” for the banner.

      Have you added your Ids for the Google Admob?

      Let me know if it solves your issue, otherwise we’ll continue to investigate.

  8. Douglas Dias Simao

    nOT SURE WHY FOR ME IT IS NOT WORKING, DO YOU HAVE A DEMO (GITHUB SOURCE) ?

    • Marco Troncone

      Yes, I’ll try to publish it this afternoon (I’ll write the link on the post and on a message).

      Meanwhile If you give me more information, I can try to help you. What problem do you have with the plugin?

    • Marco Troncone

      Hi Douglas,

      I’ve added the demo project on Github. You can download it here: https://github.com/marcojak/TestMTAdmob
      If you have any issue with it let me know, and I’ll try to help you

  9. Mitch H.

    Is there the ability to add test device ID’s so the ads will display when testing on physical devices vs. the emulator? I’ve tried adding a test Device in the MainActivity.cs after the MobileAds.Initialize but I still receive the error in the App output that the ads fail to load and to add the test device.

    • Mitch H.

      Figured it out – sorry I didn’t realize the Test devices were part of CrossMTAAdMob.Current. Great plugin. Many thanks.

  10. jay24

    Hello,

    I integrated MarcTron.Admob into my project and received several bugs. I downloaded and ran the example from Github. Also the version of Github shows after compiling 117 errors.
    What am I doing wrong?

    I’m really desperate, I would be very happy about any help.

    I am using:
    Visual Studio Community 2019 for Mac
    Version 8.0.8 (build 2)
    Xamarin.Mac 5.6.0.2

    The first 5 error are:
    /Users/test/Downloads/TestMTAdmob-master/TestMTAdmob/TestMTAdmob.iOS/clang: Error: linker command failed with exit code 1 (use -v to see invocation) (TestMTAdmob.iOS)

    /Users/test/Downloads/TestMTAdmob-master/TestMTAdmob/TestMTAdmob.iOS/MTOUCH: Error MT5214: Native linking failed, undefined symbol: _kDFPSimulatorID. This symbol was referenced by the managed member Google.MobileAds.DoubleClick.Request.SimulatorId. Please verify that all the necessary frameworks have been referenced and native libraries linked. (MT5214) (TestMTAdmob.iOS)

    /Users/test/Downloads/TestMTAdmob-master/TestMTAdmob/TestMTAdmob.iOS/MTOUCH: Error MT5211: Native linking failed, undefined Objective-C class: DFPInterstitial. The symbol ‘_OBJC_CLASS_$_DFPInterstitial’ could not be found in any of the libraries or frameworks linked with your application. (MT5211) (TestMTAdmob.iOS)

    /Users/test/Downloads/TestMTAdmob-master/TestMTAdmob/TestMTAdmob.iOS/MTOUCH: Error MT5211: Native linking failed, undefined Objective-C class: DFPCustomRenderedAd. The symbol ‘_OBJC_CLASS_$_DFPCustomRenderedAd’ could not be found in any of the libraries or frameworks linked with your application. (MT5211) (TestMTAdmob.iOS)

    /Users/test/Downloads/TestMTAdmob-master/TestMTAdmob/TestMTAdmob.iOS/MTOUCH: Error MT5214: Native linking failed, undefined symbol: _GADUnifiedNativeStarRatingAsset. This symbol was referenced by the managed member Google.MobileAds.UnifiedNativeAdAssetIdentifiers.StarRatingAsset. Please verify that all the necessary frameworks have been referenced and native libraries linked. (MT5214) (TestMTAdmob.iOS)

    • Marco Troncone

      Hi Jay24.

      The problem is that you need to install also the package Xamarin.Google.iOS.MobileAds in your iOS project.
      Do it and it will work fine.

      I’ve updated the plugin to the version 1.3 so it’s better if you can update the MTAdmob package as well.

  11. BARIÅž

    HI FIRST OF ALL THANK YOU FOR THIS WONDERFUL PLUGIN. EVERYTHING WORKS FINE BUT HOW DO I CHECK IF THE VIDEO HAS BEEN UPLOADED. ALSO HOW DO I USE THE CONTROLS TO AVOID GIVING POINTS WHEN THE VIDEO IS CLOSED. I’M SORRY FOR MY BAD ENGLISH.

    • Marco Troncone

      Hi Baris,
      Thank you for your comment.

      I think you are talking about the Rewarded Video.
      In this case you can use the OnRewardedVideoAdLoaded event to see when a video is loaded.

      To control is the user has seen the video you can use the event OnRewarded. This event will be called if and only if the uses has watched the video to get a reward.

      I hope it can help you.

      For any questions, ask me and I’ll be happy to reply

      Marco

  12. jASON BERNIE

    hello Marco, thank you for your great plugin, I am testing the Plugin and i can get in debug mode the test ads without problem, but when i change for the real app_id and ad_id of my admob real account, OnRewardedVideoAdLoaded SAYS IS NOT LOADING, CAN YOU

  13. jASON BERNIE

    hello Marco, thank you for your great plugin, I am testing the Plugin and i can get in debug mode the test ads without problem, but when i change for the real app_id and ad_id of my admob real account, OnRewardedVideoAdLoaded SAYS IS NOT LOADING, when I see the OnRewardedVideoAdLoaded event, it says false for real ads id (the ads id and the account have many time of created), what do you think can be the problem ?

    • Marco Troncone

      Hi Jason,
      Is this a new Google account?
      Consider that for the first few hours or days (up to 48 hours if I’m correct), it’s possible that you can only see the test ads and not the real ads.
      Otherwise if this is not the case, are you sure that you have used the correct publisherId and the correct AdsId?

  14. cEMoZGURA

    thank you for your great plugin, BUT Ä° CANT LOAD MY REWARDVÄ°DEOS

  15. Stoica Dragos-Octavian

    Hi, thanks FOR YOUR LIBRARY, REALLY USEFUL.

    i’VE TESTED A COUPLE OF THINGS AND THE VIDEOS AND INTERSTITIALS ARE WORKING FINE. tHE ONLY THING WHICH IS NOT WORKING ARE THE BANNERS.

    i’VE INSTALLED YOUR PLUGIN AND HERE CODE:

    xAML:

    mAIN aCTIVITY:

    MobileAds.Initialize(ApplicationContext, “ca-app-pub-2199979791362991~5921581412”);

    mANIFEST:

    tHE ADDS ARE NOT DISPLAYED. i AM USING xAMARIN 3.

    tHANKS

    • Marco Troncone

      Hi,

      probably it depends on the banner size.
      Sometimes there is not enough height to show a banner.
      Just for a test, try to add to the admob View, the property heightRequest = 60.
      If it works then this will solve your problem.
      If it doesn’t work, we can find a possible solution.

      cheers,

      Marco

  16. Jason Javaher

    Hi, as soon as I install this nuget package to my ios project I get a lot of Linking errors :/ Android works just fine and on Ios I did install the mobileads nuget package as you suggested. I’m running latest version of everything on Visual studio 2019. Have you seen this? let me know if you want me to send you the exact error messages. I’ll add the first one just as an example:

    mmon.targets(804,3): error : linker command failed with exit code 1 (use -v to see invocation)
    2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(804,3): error MT5214: Native linking failed, undefined symbol: _kDFPSimulatorID. This symbol was referenced by the managed member Google.MobileAds.DoubleClick.Request.SimulatorId. Please verify that all the necessary frameworks have been referenced and native libraries linked.
    2>C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Xamarin\iOS\Xamarin.iOS.Co

    • Marco Troncone

      Hi Jason,
      Not sure why you have this issue. I’d suggest to remove and install again the libraries (Admob and the Google ads for iOS).

      Have you tried the test project to see if it works for you?

  17. Jason Javaher

    REmoving, cleaning and reinstalling all the packages worked. I don’t know why I didn’t try that myself 🙂 Thanks a bunch buddy!

  18. Anthony

    Great job!, have you thought about adding the “keywords” property like the one in AdMob?

    • Marco Troncone

      Hi Anthony,
      What do you mean?
      If it’s a feature common in Android and iOS, I could add it if requested.

  19. Eric

    Hi Marco, thank you for your great plugin.
    When using Banner Ad, how to avoid blank space if there is no impression, sometime many requests but less impressions, especially in iOS app.

    • Marco Troncone

      Hi Eric,

      you could intercept the banner events, and show the banner only if you get the event that the ads has been loaded correctly.

      • Eric

        Thank you for your quick reply. But how do i check if banner ad not been loaded? which banner event should I use? Could you give me some guidance?

  20. Jason Javaher

    Hi Marco,
    One more Issue, I’m not sure why but the Reward Ads are not being loaded in IOS (works perfectly in Android) I’ve checked and double checked the Ad Unit ID and it doesn’t seems to want to load it. The “OnRewardedVideoAdLoaded” isn’t even being fired. Have you seen this? I’m on the latest version of everything including your awesome plugin.

    Also, Any way to set Smart Banner as the banner size Choice?

    • Marco Troncone

      Hi Jason,

      Thank you.
      I’ve tested the new version on iOS (Simulator and device) and it works fine.
      Have you tried to see the last code I put on github?
      I totally changed it to show how to use the rewarded videos in multiple pages. Let me know if it works.

      In this moment the banners for iOS and Android are SmartBanner.
      I’m planning in the next version to add the possibility to change this option but for now SmartBanner should work well on all screens

  21. Vincent Castagna

    hey. Thanks for this awesome plugin. Any plans for an open source code ? Would be great !

    • Marco Troncone

      Actually yes.
      I’m publishing a new version that fixes some issues with iOS & events, and after that I’m thinking to make it open source so that more people can (hopefully) contribute to it.

      Out of curiosity, why would you like to see it open source? isn’t easier to just use the nuget package?

      Cheers,
      Marco

      • Vincent Castagna

        Yes its always easier to consume the nugget 🙂 . Even if your work is great, I would like to see how you implemented it and to participate (there’s always improvements to bring while xf versions & google admob go on. in case one day you have no time to maintain it for any reason, I dont want to be stuck.

  22. John

    Great plugin but I have a problem. The banners works for me the test one is showing, the interistal ad also is showing for me (when made from c#) but:

    1) My own ads from my admob account are not showing Im receving these errors:

    08-22 12:18:26.272 W/DynamiteModule(18700): Local module descriptor class for com.google.android.gms.ads.dynamite not found.
    08-22 12:18:26.277 D/DynamitePackage(18700): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
    08-22 12:18:26.285 I/Ads (18700): This request is sent from a test device.
    08-22 12:18:26.430 W/DynamiteModule(18700): Local module descriptor class for com.google.android.gms.ads.dynamite not found.
    08-22 12:18:26.433 D/DynamitePackage(18700): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
    08-22 12:18:26.436 I/Ads (18700): This request is sent from a test device.
    08-22 12:18:26.485 W/Ads (18700): Not retrying to fetch app settings
    08-22 12:18:26.990 I/Ads (18700): Ad failed to load : 3
    08-22 12:18:26.991 I/Ads (18700): Ad failed to load : 3

    2) The native ad also is not working not even the test one (ca-app-pub-3940256099942544/2247696110)

    Can you help me fix this please?

  23. Steeven

    Hi Marco,

    First of all, thanks a lot for your work, it is awesome 🙂

    I’m using Interstitial Ad on my application but the ad is not showing in fullscreen. In portrait mode, it’s stuck at the left of the screen https://ibb.co/f9tPhJ5

    Any idea if it is a bug ?

    • Marco Troncone

      Hi Steeven

      Thank you for your compliments.

      I’m not sure if it’s a bug or not, but i’ll have a look and I’ll let you know

      Cheers,

      marco

  24. Yousuf

    Thank you for this plugin.
    The plugin is very useful, the app works well but when I use android 9 Pie version and I run the app on my phone crashes the app, I know that the bug is in
    xamarin.googleplayservices.ads
    Or
    Xamarin.GooglePlayServices.Ads.Lite
    But I don’t know how I can make it work.

    • Marco Troncone

      Hi Yousuf

      Add this to your AppManifest

      Remember to use your actual APPID!

      Cheers,

      Marco

      • Yousuf

        Thank you for the reply.
        What should I add to AppManifest,
        Can you explain more?

        • Marco Troncone

          Hi Yousuf,

          Sorry for some reason, the blog didn’t copy the code to add to the AppManifest.
          The code is:
          meta-data android:name=”com.google.android.gms.ads.APPLICATION_ID” android:value=”ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy”

          Marco

  25. Mark Zhukovsky

    This is very helpful, as it is messy and confusing to implement oneself. THank you. UWP support would be great, but instead of admob (since i don’t believe they have a windows sdk) it can just leverage microsoft advertising and only implement the banner and interstitial ads on UWP: https://docs.microsoft.com/en-us/windows/uwp/monetize/developer-walkthroughs

    • Marco Troncone

      Hi Mark,

      Thank you.

      Are you suggesting I should add the UWP implementation?
      If people are still using UWP, I could actually implement it in a new version.

      Cheers,
      Marco

      • Vincent castagna

        This would definetly be a good idea. We are using UWP as well, delivering all platforms … Have you considered putting your plugin on github ? Would be glad to help you with some PRs 😉

      • Mark ZHUKOVSKY

        Yes would be great for projects that leverage all 3 platforms. Or perhaps at a minimum make the library do nothing when added to UWP project so that it doesn’t break without extra code changes on dev’s side.

  26. MarcTron.Admob version 1.4.3 is here | Xamarin eXpert

    […] There are many other things you can do with this great plugin for Admob. You can find the full documentation here: https://www.xamarinexpert.it/admob-made-easy/ […]

  27. Andy

    Thank you for your library.
    ios is fine, but android is not working banner,
    i also check your git test admob sample, it’s same error for banner.
    how can I use xamarin android service.

    • Marco Troncone

      Hi Andy,
      What problem do you have in Android?
      Let me know and I’ll help you with it.

      Did you add in your manifest the metadata for your APPLICATION_ID?
      meta-data android:name=”com.google.android.gms.ads.APPLICATION_ID” android:value=”ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy”

      Anyway I’m having a look at the plugin and demo code and I’ll update it if necessary.

      • Andy

        Thank you for your reply,

        i already added this code.

        Android

        properties/AndroidManifest.xml

        MainActivity.cs
        OnCreate
        MobileAds.Initialize(ApplicationContext, “ca-app-pub-**********~**********”);

        Forms
        App.xaml
        add

      • Andy

        Android

        properties/AndroidManifest.xml
        application android:label=”****”
        meta-data android:name=”com.google.android.gms.ads.APPLICATION_ID” android:value=”ca-app-pub-*********~********” /
        activity android:name=”com.google.android.gms.ads.AdActivity” android:configChanges=”keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize” android:theme=”@android:style/Theme.Translucent” /
        /application
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /
        <uses-permission android:name="android.permission.INTERNET" /

        MainActivity.cs
        OnCreate
        MobileAds.Initialize(ApplicationContext, "ca-app-pub-**********~**********");

        Forms
        App.xaml
        add

        • Marco Troncone

          Hi Andy,
          what error do you get?
          Anyway there is a new version of the plugin (1.4.4).
          I’d suggest you to update it.
          If the error persists, Can you tell me what error do you get?

          Thanks,
          Marco

      • Steve Link

        Hi Marco,
        I have added this code and updated the version of your plugin. The error is:
        Java.Lang.RuntimeException
        Message=Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

        ******************************************************************************
        * The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers *
        * should follow the instructions here: https://goo.gl/fQ2neu to add a valid *
        * App ID inside the AndroidManifest. Google Ad Manager publishers should *
        * follow instructions here: https://goo.gl/h17b6x. *
        ******************************************************************************

        • Marco Troncone

          Hi Steve,

          You have to add this line in your AndroidManifest, as in this example (remember to change the value of the Application_ID):

          meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"

          let me know if it works.

          Marco

          • Steve Link

            Thanks Marco,
            I had been fighting with that specific problem thinking it would be fixed with a new update. I was adding those lines to the generated AndroidManifest instead of the source. It is all fixed now and Android has been published. This afternoon the journey of publishing on Apple store begins, maneuvering their hurdles to a final victory.

  28. MTAdmob is now Open Source | Xamarin eXpert

    […] Again if you need a tutorial, you can have a look at https://www.xamarinexpert.it/admob-made-easy/ […]

  29. activ247

    First of all thank you for your work, it has greatly facilitated the use of Admob, Thank you.
    Maybe it has nothing to do with your nuget, but since it was updated I can no longer compile it for iOS, before writing I have reviewed it, I have even returned to the previous version from a backup and it was fine, but when updating the package, then it gives These mistakes, if you knew where to look, it would help. Greetings

    * linker command failed with exit code 1 (clang)
    * framework not found GoogleSignIn ( error MT5209)
    * Native linking failed, please review the buld log and the user flags provided to gcc: -ObjC- lsqlite3 – ObjC -lz -lsqlite3 (MT5201)
    * Native linking failed. Please review the build log (MT5202)

    • Steve Link

      It sounds like you may not have included Xamarin.Google.iOS.MobileAds nuGet package

    • Marco Troncone

      Hi,

      Thank you for your message.
      The problem comes from the new Google.MobileAds.
      To solve it, you have to install Xamarin.Google.iOS.SignIn 4.4.0 (Exactly this version, not the newer one).

      This will solve the issue.

      Let me know if it works.

      Marco

  30. Alper

    Marco we get this eror Java.Lang.RuntimeException: ‘Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException:

    how can we pass this error? i tried a lot of times but i cannot solve this problem :////// can you explain with images ?

    • Marco Troncone

      Hi Alper,

      You need to edit your AndroidManifest in your Android project.

      Inside “application” you need to add this line:

      meta-data android:name=”com.google.android.gms.ads.APPLICATION_ID” android:value=”ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy”

      It’s written in https://www.xamarinexpert.it/admob-made-easy/ undert the “Android Project (Important)”

      This will fix the error. Remember to replace ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy with your ID

      Cheers,

      Marco

  31. Jayaruban

    what could be the reason that Android does not show the test advertising? It works on iOS.

    • Marco Troncone

      Hi,

      I can imagine two main causes:
      1) The IDs are not correct for the Android project.
      2) The Ads doesn’t have enough space to appear.

      In the first case, just use the correct IDs.
      In the second case, try to set the HeightRequest value (50 for phones and 90 for tablets).

      This should solve the issue for Google Admob on Android.

      Let me know if it solves the issue.

      Cheers,

      Marco

      • Jayaruban

        Hi, thanks. Now it is working. It was the height. I have set it to 50 now.

        Regards

        Jayaruban

  32. Rizvi Developers

    I am Facing Problem in Interstitial Ads. In Your post Above You USe this code MobileAds.Initialize(ApplicationContext, “ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx”); AND in your github repository you have use CrossMTAdmob.Current.ShowRewardedVideo();
    Please Clear this Point? Which Code I Use And Where To Use

    • Marco Troncone

      Hi,

      The first code
      MobileAds.Initialize(ApplicationContext, “ca-app-pub-xxxxxxxxxxxxxxxx~xxxxxxxxxx”)
      is used to initialize the Google ads plugin and it’s mandatory.

      The second line of code is to actually show a rewarded video.
      So you always have to use the first line (in the new version you have to add a line in your AndroidManifest as well), an you use the second line every time you want to show a rewarded video (remember to load one before showing it).

      I hope this helps you.

      Marco

  33. Rizvi Developers

    I’m wondering. What a Issue ? I test my app on physical android device. When i depoly the App with WIFI running the ads display Easily without any error, BUT when i USE my SIM Data Connection, Nothing happens and ads are not showing . I have also Used another physical android device, but the Problem remains same . “In short WIFI show Ads & Mobile Data doesn.t Show Ads” …… Please Help Me Regarding this Issue.

    • Marco Troncone

      Hi Rizvi, do you have the same issue with the test app for MTAdmob? Try that one and see if it works there, maybe is something related to your App_ID or maybe to your data blocking the ads. I can tell you that the library makes no difference between Wifi and SIM Data.

  34. David

    AdsClicked and AdsOpened not work for banners…

  35. Ruchita

    Hey Marco,

    Thanks a bunch for this awesome plugin. It saved me a lot of time. Great job!

    I am stuck at one point though and was hoping you could help me!

    I am almost done with my implementation but now I am facing a problem with testing the ad on my iOS test device. Even when I set “CrossMTAdmob.Current.TestDevices”, it only worked for Android device.

    Initially I though I was doing something wrong, but when I checked your github repo, I saw that you have implemented this only for Android. Any plan of adding this for iOS plugin as well?

    If not, can you give me some workaround for this?

    • Marco Troncone

      Hi,

      I’ll definitely implement it, I just forgot :).

      If you know how to do it, you can create a pull request for this feature otherwise I’ll do it.

      For now, you can try to use test ads Id for your app and banners

      Cheers,

      Marco

      • Ruchita

        Thanks for quick response!

        Unfortunately, I am under tight schedule so not sure when I will be able to create this pull request. But will definitely do it if you have not been able to do it by the time I am done with my work. 🙂

      • Nicolas Gorse

        Hello,

        Did you have a chance to do it? I have the latest version but CrossMTAdmob.Current.TestDevices doesn’t seem to work on iOS.

        Thanks,

        N.

  36. Alejandro Botero

    I am having the exact same issue with the packages… I tried with MarcTron.AdMob v1.4.5, Xamarin.Google.iOS.MobileAds v7.47 and Xamarin.Google.iOS.SignIn v5.0.1.

    Finally, I’ve been able to get it working by uninstalling Xamarin.Google.iOS.SignIn and downgrading Xamarin.Google.iOS.MobileAds to v7.38. I publish this for anyone who also get in trouble to make it work on iOS.

    And Marco, if you get to discover where the problem is, please update your plugin. I’d like to thank you, because this plugin is a lifesaver, you made all this Ads framework simple.

    • Marco Troncone

      Thank you very much for your comment. Things like this give me the strength to improve this and other packages. Thanks again

      • Alejandro Botero

        I got it to work in the 7.47 version of MobileADs. I had to install other dependences and uninstall SignIn.

        The working NuGet packages are:
        – MarcTron.Admob (1.4.5)
        – Xamarin.Google.iOS.Core (3.1.0.1)
        – Xamarin.Google.iOS.MobileAds (7.47.0)

  37. Maverick

    Hello Marco Troncone,
    I would also like to thank you for your grate plugins.

    Question i have is:
    the Ads were showing for a few days now it seems the ads have stopped showing in my app, I have asked a few people that have the app downloaded and they say the same thing. The app was showing Ads now nothing

    • Marco Troncone

      Hi Maverick. If the app was already published I don’t think the issue is related to the plugin. Are you sure, your Ads ID are still valid? Is it possible that Google blocked them?

      • Maverick

        I checked and I didn’t see anything saying they were blocked

      • Maverick

        When i put the test ad id’s back in it works..But when i Add my own id’s its not working?

  38. gjhdigital

    Help please!
    I cant get the test ads to show up.
    Im testing using the Google test ads on an android Amazon Fire HD10 running VS2019 community with Xamarin.Forms v4.4.0.991537

    The placeholder is there but no ads show up.
    Thanks in advance.

    My implemented code:

    My AndroidMainfest.xml code if have

    My mainactivity code if have
    // Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713
    MobileAds.Initialize(ApplicationContext, “ca-app-pub-3940256099942544~3347511713″);

    My xaml code if have
    xmlns:controls=”clr-namespace:MarcTron.Plugin.Controls;assembly=Plugin.MtAdmob”
    and

    xaml.cs code if have
    using MarcTron.Plugin.Controls;

  39. gjhdigital

    Hi I have the Android project working but I just downloaded your latest project from you git hub, I’m on a mac VS2019 and updated all XF nugets and im getting these errors in your project. Any thoughts on what might be the issue? Thanks in advance.

    Forms Nuget:
    MarcTron.Admob v1.4.5
    Xamarin.Essentials v1.3.1
    Xamarin.Forms 4.4.0.991640
    Xamarin.GoogleiOS.SignIn 5.0.1.1

    IOS project Nuget:
    MarcTron.Admob v1.4.5
    Xamarin.Essentials v1.3.1
    Xamarin.Forms 4.4.0.991640
    Xamarin.GoogleiOS.SignIn 5.0.1.1
    Xamarin.GoogleiOS.MobileAds 7.47.0.1

    Build FAILED.

    MTOUCH : warning MT5215: References to ‘System’ might require additional -framework=XXX or -lXXX instructions to the native linker
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: GTMAppAuthFetcherAuthorization. The symbol ‘_OBJC_CLASS_$_GTMAppAuthFetcherAuthorization’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: GTMKeychain. The symbol ‘_OBJC_CLASS_$_GTMKeychain’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: GTMOAuth2KeychainCompatibility. The symbol ‘_OBJC_CLASS_$_GTMOAuth2KeychainCompatibility’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDAuthState. The symbol ‘_OBJC_CLASS_$_OIDAuthState’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDAuthorizationRequest. The symbol ‘_OBJC_CLASS_$_OIDAuthorizationRequest’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDAuthorizationService. The symbol ‘_OBJC_CLASS_$_OIDAuthorizationService’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDIDToken. The symbol ‘_OBJC_CLASS_$_OIDIDToken’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDServiceConfiguration. The symbol ‘_OBJC_CLASS_$_OIDServiceConfiguration’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5211: Native linking failed, undefined Objective-C class: OIDURLQueryComponent. The symbol ‘_OBJC_CLASS_$_OIDURLQueryComponent’ could not be found in any of the libraries or frameworks linked with your application.
    MTOUCH : error MT5210: Native linking failed, undefined symbol: _OBJC_METACLASS_$_GTMAppAuthFetcherAuthorization. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    MTOUCH : error MT5210: Native linking failed, undefined symbol: _OIDOAuthErrorResponseErrorKey. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    MTOUCH : error MT5210: Native linking failed, undefined symbol: _OIDOAuthTokenErrorDomain. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    MTOUCH : error MT5210: Native linking failed, undefined symbol: _OIDResponseTypeCode. Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.
    MTOUCH : error MT5201: Native linking failed. Please review the build log and the user flags provided to gcc: -ObjC -lc++ -lsqlite3 -lz -ObjC -lsqlite3 -ObjC -lz -lsqlite3
    MTOUCH : error MT5202: Native linking failed. Please review the build log.
    clang : error : linker command failed with exit code 1 (use -v to see invocation)
    1 Warning(s)
    16 Error(s)

    • Marco Troncone

      Hi!

      I copy here what Alejandro wrote few comments earlier:

      “I got it to work in the 7.47 version of MobileADs. I had to install other dependences and uninstall SignIn.

      The working NuGet packages are:
      – MarcTron.Admob (1.4.5)
      – Xamarin.Google.iOS.Core (3.1.0.1)
      – Xamarin.Google.iOS.MobileAds (7.47.0)”

      Try the same, it will work.

      Cheers

      • gjhdigital

        yes! thank you that worked! I added those nugets in the ios project and in the forms project and removed the .signin nuget from both and your iOS app loads with the test advertisement.
        thanks again for a great and easy to use plugin!

  40. Maverick

    Would there be any way to have multiple ad id’s in a list and have it randomize each time it displays?

    • Marco Troncone

      Ideally it’s possible but why to use random IDs for the same banner?

      • Maverick

        my idea behind it is to change out the id’s each time the user goes to a different page. Also I thought it would make it easier to develop with. As of now I have to change out my id’s and put test ones in when i’m working on the app

        • Marco Troncone

          You can set the ads id on every single page directly on the xaml, so you can have 100 different IDs for 100 different pages

          • Maverick

            Yes that is what i’m currently doing. But I thought for testing I have to go to every page and make sure I put admob test id’s in just so google doesn’t red flag me for using an emulator with my ad ids

  41. myshifter

    Hi Marco, thanks for the great plugin!
    First, you should update your code examples in this page to your new version, this would eleminate some confusion maybe.
    Second, I have some problems with the interstitials… I try to load and show a interstitial ad and after closing the ad open modal the next page. But the next page is not shown. It is in the modalstack, but not visible. I just have this issue with the iOS part, android works like a charm. Is there something I have to do another way in iOS?
    This is the code:
    CrossMTAdmob.Current.ShowInterstitial();
    await Application.Current.MainPage.Navigation.PushModalAsync(new View.Test(testInfo), false);
    When I delete the first line, View.Test opens like expected, but with this line, the interstitial is open and after closing I just see the current page, not the View.Test

  42. jeanpaul

    when i request a rewarded video this error appear
    no overload for method ‘ShowRewardedVideo’ takes 1 arguments
    ?

  43. Seb

    Great Job. I just follow your tutorial today to implement Ads on my apps. It’s work fine on Android but for iOS I have to use Xamarin.Google.iOS.MobileAds 7.47.01 and Xamarin.Google.iOS.SignIn 4.4.0. Latest will cause lot of Build Errors. Maybe because I have to use Xamarin.Firebase.iOS.Analytics 6.0.4.1 for another plugin and it’s not also the lasts stable version of it.

Leave a Reply

%d bloggers like this: