MTAdmob for MAUI 3.0: AdMob on Google's Next-Gen SDK
MTAdmob for .NET MAUI 3.0 is out. It's the biggest change under the hood since the plugin was first released: on Android, it now runs on Google's Mobile Ads Next-Gen SDK, which Google has made the preferred SDK for Android apps.
The good news is that you'll hardly notice. The public API is the same as in 2.x: same namespace, same controls, same events, same method signatures. For most apps, updating is a package update and a one-line change in the csproj.
What changes
On Android, the plugin has moved from the legacy Google Mobile Ads SDK to the Next-Gen SDK. On iOS, nothing changes: Google hasn't released a Next-Gen SDK for iOS, so the plugin keeps using the Google Mobile Ads SDK 12.x.
| 3.x | 2.x | |
|---|---|---|
| Android SDK | Google Mobile Ads Next-Gen SDK | Legacy Google Mobile Ads SDK |
| iOS SDK | Google Mobile Ads SDK 12.x | Google Mobile Ads SDK 12.x |
| Android minimum version | Android 7.0 (API 24) | Android 5.0 (API 21) |
| Mediation on Android | AdMob mediation only | Any mediation platform |
| Status | Current version | Still maintained |
Use 3.x unless your app has to support Android versions below 7.0, or mediates through a platform other than AdMob. In those cases stay on 2.x, which I'll keep maintaining, until you can move.
How to update from 2.x
Update Plugin.MauiMTAdmob to 3.x.
Raise your Android minimum version to 24 in your app's csproj:
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">24.0</SupportedOSPlatformVersion>Leave your code as it is.
UseMauiMTAdmob(),CrossMauiMTAdmob.Current,MTAdView,MTNativeAdView, the events and the consent calls are all unchanged. Keep the AdMob App ID in yourAndroidManifest.xml: the consent SDK still reads it from there.If you have a licence, check that your key is valid for 3.x (more on that below).
If you forget step 2, the build fails with "minSdkVersion cannot be smaller than version 24".
What behaves differently on Android
The API is the same, but the Next-Gen SDK does a few things its own way:
- Initialisation runs in the background. The Next-Gen SDK has to finish initialising before it can load ads. The plugin starts it inside
Initon a background thread and queues anyLoad*,SetAppMuted,SetAppVolumeorOpenAdInspectorcall made in the meantime, so loading an ad right afterInitkeeps working. - Error codes are the same, the domain isn't.
MTEventArgs.ErrorCodekeeps Google's numeric codes (2= network error,3= no fill...), whileErrorDomainis nowcom.google.android.libraries.ads.mobile.sdk. If you check the domain anywhere, update it. - Interstitials ignore the back key, as the Next-Gen SDK does. Users close them with the close button.
- Anchored adaptive banners (
AnchoredAdaptive, andSmart, which the Next-Gen SDK removed) use Google's large anchored adaptive size, so they can be slightly taller. - Banner refreshes raise
AdsLoadedagain, and the banner's height follows the new ad. - Child-directed and under-age tags are mapped to the Next-Gen age treatment as Google documents it: if either is set, the request gets the child treatment.
- With AdMob mediation, the first request can go out before every adapter has initialised. The Next-Gen SDK can take up to 30 seconds to report adapters, so the plugin doesn't wait for it (Google's own sample doesn't either).
New in 3.0
Impression-level ad revenue
OnAdPaid is raised every time an ad earns money, for every format: banners, interstitials, rewarded, rewarded interstitials, app open and native ads. You get the format, the ad unit, the value and currency, the precision and the ad network that served it, ready to forward to Firebase or your attribution SDK.
CrossMauiMTAdmob.Current.OnAdPaid += (sender, e) =>
{
// e.Value is in units of e.CurrencyCode (e.ValueMicros is the raw value in micros)
Debug.WriteLine($"{e.AdFormat} {e.AdUnitId}: {e.Value} {e.CurrencyCode} ({e.Precision})");
};
Remember to turn on impression-level ad revenue in your AdMob account settings, otherwise the values are empty.
Ad Inspector
Google's Ad Inspector is an in-app overlay that shows every ad request your app makes, its result and the mediation waterfall. It's the quickest way to find out why an ad isn't showing. It opens on test devices, or on devices where you enabled it from the AdMob UI.
CrossMauiMTAdmob.Current.OnAdInspectorClosed += (sender, e) =>
{
if (e.ErrorCode != null)
Debug.WriteLine($"Ad Inspector error: {e.ErrorMessage}");
};
CrossMauiMTAdmob.Current.OpenAdInspector();
Privacy, content mapping and targeting
PublisherPrivacyPersonalizationStatesets Google's publisher privacy treatment.Disabledturns off ad personalisation for every request, whatever the other signals say.ContentUrlandNeighboringContentUrlstell Google what the user is looking at, so it can serve more relevant ads.CustomTargetingsends key-value pairs for your Google Ad Manager line items.
CrossMauiMTAdmob.Current.ContentUrl = "https://www.example.com/recipes/carbonara";
CrossMauiMTAdmob.Current.NeighboringContentUrls = new() { "https://www.example.com/recipes/amatriciana" };
CrossMauiMTAdmob.Current.CustomTargeting = new() { { "section", "recipes" } };
Better native ads on Android
Native ads on Android now resize to their template, so their pieces no longer spill outside the native ad view. If the native ad validator on your test device complained about "Advertiser assets outside native ad view", 3.0 fixes it.
While you're there, give the MTMediaView in your template at least 120x120: Google requires it for video ads, and the validator reports anything smaller. In a Grid, use Auto rows around the media view rather than * rows, which can shrink it.
Licence keys
The free version keeps working as before. If you have a licence:
- A 1 Major Version licence is valid for the major version it was bought for, including all its minor updates. A key bought for 2.x keeps working on every 2.x release, but it doesn't unlock the licensed features on 3.x: for those you need a 3.x key, or you can stay on 2.x.
- A perpetual licence (Single Supporter and Multi Supporter) is valid for every version, 3.x included.
If your key isn't valid for the version you're using, the plugin logs "The key was issued for version ... of the plugin and is not valid for version ..." and runs as the free version. You can get a 3.x licence on the MTAdmob for MAUI page.
Learn more
The MTAdmob for MAUI guide has a new Version 3 (Next-Gen) section with everything in this post, and the rest of the guide is up to date with 3.0.
If you find a problem with 3.0, or something doesn't behave the way it did on 2.x, let me know at [email protected].
MTAdmob for .NET MAUI
Banners, interstitials, rewarded, native and app open ads with GDPR consent, on Android and iOS, in a few lines of code.
Discover MTAdmob for MAUI