Migrate to the new Google Mobile Ads C++ SDK Stay organized with collections Save and categorize content based on your preferences.
Instead of the Google Mobile Ads C++ SDK, consider using theiOS andAndroid SDKs fromAdMob. For support, reach out to theGoogle Mobile Ads SDK Technical Forum.
The release of theFirebaseC++ SDK v9.1.0 introduces a newGoogle Mobile Ads C++ SDK.
The Google Mobile Ads C++ SDK is a new API surface that incorporates the majorbreaking changes made to the Firebase AdMob C++ SDKs for iOS and Androidin 2021 and 2022, including the removal of deprecated APIs, and a new flow whenworking with full screen ad types.
The old Firebase AdMob C++ SDK (firebase::admob) has been marked deprecatedand will not be receiving any updates or bug fixes moving forward.
Both the new Google Mobile Ads C++ SDK (firebase::gma) and the oldFirebase AdMob C++ SDK (firebase::admob) will remain part of the buildarchives for theFirebaseC++ SDK during the Firebase AdMob C++ SDKdeprecation window.
Legacy API removal
The following APIs have been removed from the Google Mobile Ads C++ SDK in theirentirety.
RewardedVideoAd
AdMob'sRewardedVideoAd namespace has been replaced withRewardedAd class.RewardedAd behaves similarly toInterstitialAd butincludes an additionalRewardedAdListener to receive notification of itemrewards.
NativeExpressAds
AdMob'sNativeExpressAd had already been marked as deprecated in eachFirebase AdMob C++ SDK. ThereforeNativeExpressAd is not included in thenew Google Mobile Ads C++ SDK.
SDK namespace change
The SDK has relocated to a new namespace, and it has a new directory structure:
Namespacefirebase::gma
The sources of the new Google Mobile Ads C++ SDK are in thefirebase::gmanamespace. The olderfirebase::admob namespace has been deprecated along withthe Firebase AdMob C++ SDK.
Directory structure
Header files have moved to a new directory inside the build archive:
| Deprecated Firebase AdMob C++ SDK | New Google Mobile Ads C++ SDK |
|---|---|
include/firebase/admob | include/firebase/gma |
Library
The Firebase AdMob C++ SDK will be provided as a static library within theFirebaseC++ SDK build archive:
iOS
| Deprecated Firebase AdMob C++ SDK | New Google Mobile Ads C++ SDK |
|---|---|
firebase_admob.xcframework | firebase_gma.xcframework |
Android
| Deprecated Firebase AdMob C++ SDK | New Google Mobile Ads C++ SDK |
|---|---|
libfirebase_admob.a | libfirebase_gma.a |
Class, enum, and struct migrations
The table below lists specific classes, enums, and structs that changed or havebeen removed. Here's a summary:
BannerViewis renamed toAdView.NativeAdExpressViewis removed.- The
RewardedVideonamespace is replaced with aRewardedAdclass. - The
PresentationStateenumeration and listeners are removed andreplaced withAdListenerandFullScreenContentlisteners. The following parameters are removed as per-ad configuration parametersin
AdRequests:- the configuration of test device IDs
- the targeting of advertisements based on age
Instead, these parameters can now be configured in
RequestConfigurationwhich is a global setting that will affect all subsequent ad loads.
Deprecatedfirebase::admob namespace | Newfirebase::gma namespace |
|---|---|
AdSizeType (enum) | AdSize::Type (enum) |
BannerView | AdView |
BannerView::Listener | AdListenerAdViewBoundingBoxListenerPaidEventListener |
BannerView::Position | AdView::Position |
BannerView::PresentationState | Removed |
ChildDirectedTreatmentState | RequestConfiguration::TagForChildDirectedTreatment |
Gender (enum) | Removed |
InterstitialAd::Listener | FullScreenContentListenerPaidEventListener |
KeyValuePair | Removed |
NativeExpressAdView | Removed |
PollableRewardListener | Removed |
RewardItem | AdReward |
RewardedVideoAd (namespace) | RewardedAd (class) |
RewardedVideoAd::Listener | FullScreenContentListenerPaidEventListenerUserEarnedRewardListener |
AdMobError (enum) | AdErrorCode (enum) |
RewardItem | AdReward |
SDK initialization
Each Google Mobile Ads C++ SDK initialization function immediately returns twostatus indicators:
An optional out parameter conveys whether a dependency error occurred beforethe initialization process started.
The return parameter is a reference to a
firebase::Future. TheFuturecontains the results of the asynchronous initialization of the mediationadapters on the device.
While the Google Mobile Ads C++ SDK may be invoked to loadAdMob-served ads assoon as the initialization function returns, other ad networks will not serveads until their corresponding medation adapter has been fully initialized. Thisprocess occurs asynchronously. Therefore, if you're using ad mediation in yourapplication, we recommend that you wait for theFuture to resolve beforeattempting to load any ads.
Before
firebase::App*app=::firebase::App::Create();firebase::InitResultresult=firebase::admob::Initialize(*app,kAdMobAppID);if(result!=kInitResultSuccess){// Initialization immediately failed, most likely due to a missing dependency.// Check the device logs for more information.return;}After
usingfirebase::App;usingfirebase::Future;usingfirebase::gma::AdapterInitializationStatus;App*app=::firebase::App::Create();firebase::InitResultresult;Future<AdapterInitializationStatus>future=firebase::gma::Initialize(*app,&result);if(result!=kInitResultSuccess){// Initialization immediately failed, most likely due to a missing dependency.// Check the device logs for more information.return;}// Poll the future to wait for its completion either in this// thread, or as part of your game loop by calling// firebase::gma::InitializeLastResult();while(future.status()==firebase::kFutureStatusPending){// Initialization on-going, continue to wait.}// future.status() is either kFutureStatusComplete or there’s an errorif(future.status()==firebase::kFutureStatusComplete&&future.error()==firebase::gma::AdErrorCodeNone){AdapterInitializationStatus*status=future.result();// Check status for any mediation adapters you wish to use.// ..}else{// Handle initialization error.}Changes toAdSize withinAdView
AdSize now contains static members of common banner ad sizes, and supportsAnchorAdaptive andInlineAdaptive ad sizes which have a dynamic height basedon the given width and the screen's current orientation.
StaticAdSize constants added tofirebase::gma::AdSize | |
|---|---|
AdSize::kBanner | Mobile Marketing Association (MMA) banner ad size (320x50 density-independent pixels) |
AdSize::kFullBanner | Interactive Advertising Bureau (IAB) full banner ad size (468x60 density-independent pixels) |
AdSize::kLargeBanner | Taller version ofkBanner, typically 320x100 |
AdSize::kLeaderboard | Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels) |
AdSize::kMediumRectangle | Interactive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels) |
Static methods infirebase::gma::AdSize to help construct instances ofAdSize | |
|---|---|
GetLandscapeAnchoredAdaptiveBannerAdSize | Creates anAdSize with the given width and a Google-optimized height to create a banner ad in landscape mode |
GetPortraitAnchoredAdaptiveBannerAdSize | Creates anAdSize with the given width and a Google-optimized height to create a banner ad in portrait mode |
GetCurrentOrientationAnchoredAdaptiveBannerAdSize | Creates anAdSize with the given width and a Google-optimized height to create a banner ad given the current orientation |
GetInlineAdaptiveBannerAdSize | Creates anAdSize most suitable for banner ads given a maximum heightThis |
GetLandscapeInlineAdaptiveBannerAdSize | Creates anInlineAdaptiveAdSize with the given width and the device's landscape height |
GetPortraitInlineAdaptiveBannerAdSize | Creates anInlineAdaptiveAdSize with the given width and the device's portrait height. |
GetCurrentOrientationInlineAdaptiveBannerAdSize | A convenience method to returnInlineAdaptiveAdSize given the current interface orientation given a specific width. |
Before
firebase::admob::BannerView*banner_view=newfirebase::admob::BannerView();firebase::admob::AdSizead_size;ad_size.ad_size_type=firebase::admob::kAdSizeStandard;ad_size.width=320;ad_size.height=50;// ad_parent is a reference to an iOS UIView or an Android Activity.// banner_ad_unit is your ad unit id for banner ads.banner_view->Initialize(ad_parent,banner_ad_unit,ad_size);After
firebase::gma::AdView*ad_view=newfirebase::gma::AdView();// ad_parent is a reference to an iOS UIView or an Android Activity.// banner_ad_unit is your ad unit id for banner ads.banner_view->Initialize(ad_parent,banner_ad_unit,firebase::gma::AdSize.kBanner);AdRequest and global configuration
Test device IDs,TagForChildDirectedTreatment, andTagForUnderAgeOfConsent(previously handled by birthday) have been removed fromAdRequest and are nowpart of a globalRequestConfiguration. Applications may invokefirebase::gma::SetRequestConfiguration() early-on in the application'slifecycle to configure these values. All subsequent ad load operations willhonor these settings once they're configured.
firebase::gma::AdRequest still exists as it provides contextual informationfor loading advertisements, including keywords and an optional content URL.
AdMob'sAdRequest C-style struct has been replaced with a class with methodswhich provide a better user experience when defining and appending to thevarious lists of information.
Here are notableAdRequest changes:
- Extras are now associated with a mediation adapter class name. Extras sentto theAdMob service should use the default class name as defined below.
- When requesting an ad, apps may pass a URL of the content they are serving.This enables keyword targeting to match the ad with other content beingdisplayed.
Before
firebase::admob::AdRequestrequest;// Keywords to be used in targeting.constchar*keywords[]={"GMA","C++","Fun"};request.keyword_count=sizeof(keywords)/sizeof(keywords[0]);request.keywords=keywords;// "Extra" key value pairs.staticconstfirebase::admob::KeyValuePairextras[]={{"extra_name","extra_value"}};request.extras_count=sizeof(extras)/sizeof(extras[0]);request.extras=kRequestExtras;// Devices that should be served test ads.constchar*test_device_ids[]={"123","4567","890"};request.test_device_id_count=sizeof(test_device_ids)/sizeof(test_device_ids[0]);request.test_device_ids=test_device_ids;// Sample birthday to help determine the age of the user.request.birthday_day=10;request.birthday_month=11;request.birthday_year=1975;// Load Ad with the AdRequest.After
// Do once after Google Mobile Ads C++ SDK initialization.// These settings will affect all Ad Load operations.firebase::gma::RequestConfigurationconfiguration;configuration.max_ad_content_rating=firebase::gma::RequestConfiguration::kMaxAdContentRatingPG;configuration.tag_for_child_directed_treatment=firebase::gma::RequestConfiguration::kChildDirectedTreatmentTrue;configuration.tag_for_under_age_of_consent=firebase::gma::RequestConfiguration::kUnderAgeOfConsentFalse;configuration.test_device_ids.push_back("1234");configuration.test_device_ids.push_back("4567");configuration.test_device_ids.push_back("890");firebase::gma::SetRequestConfiguration(configuration);// Then, more information must be provided via an AdRequest when// loading individual ads.firebase::gma::AdRequestad_request;// "Extra" key value pairs.ad_request.add_keyword("GMA");ad_request.add_keyword("C++");ad_request.add_keyword("Fun");// Content URL.ad_request.set_content_url("www.example.com");// Mediation Adapter Extras.#if defined(Android)constchar*ad_network_extras_class_name="com/google/ads/mediation/admob/AdMobAdapter";#else// iOSconstchar*ad_network_extras_class_name="GADExtras";#endifad_request.add_extra(ad_network_extras_class_name,"extra_name","extra_value");// Load Ad with the AdRequest. See next section.AdResults
LoadAd now returns aFuture containing anAdResult object for allAdView,InterstitialAd, andRewardedAd ad types. TheAdResult::is_successful method returnstrue if the ad request wassuccessfully fulfilled, orfalse if not.
On failure, theAdResult contains anAdError object with service-levelinformation about the problem, including the error code, the error message anddomain strings.
Before
firebase::Future<AdResult>future;voidload_ad(){// Assume an already created AdRequest object.future=ad_view->LoadAd(ad_request);}voidyour_game_loop(){if(future.status()==firebase::kFutureStatusComplete){if(future.error()!=firebase::admob::kAdMobErrorNone){// There was either an internal SDK issue that caused the Future to// fail its completion, or AdMob failed to fulfill the ad request.// Details are unknown other than the Future’s error code returned// from future.error().}else{// The ad loaded successfully.}}}After
firebase::Future<AdResult>future;voidload_ad(){// Assumes a previously created AdRequest object.// See "AdRequest and Global Configuration" above.future=ad_view->LoadAd(ad_request);}voidyour_game_loop(){// Check the future status in your game loop:if(future.status()==firebase::kFutureStatusComplete){if(future.error()!=firebase::admob::kAdErrorCodeNone){// There was an internal SDK issue that caused the Future to fail.}else{// Future completed successfully. Check the GMA result.constAdResult*ad_result=future.result();if(ad_result->is_successful()!=true){// GMA failed to serve an ad. Gather information about the error.constAdError&ad_error=ad_result->ad_error();AdErrorCodeerror_code=ad_error.code();conststd::stringerror_domain=ad_error.domain();conststd::stringerror_message=ad_error.message();}else{// The ad loaded successfully.}}}}AdListener events withinAdView
AdMob'sBannerView::Listener class has been replaced with two distinctlistener classes in the Google Mobile Ads C++ SDK:
AdListenertracks ad lifecycle and user interaction events.AdViewBoundingBoxListeneris invoked when theAdViewis resized or moved.
AdMobOnPresentationStateChanged callbackGoogle Mobile Ads mappings
Thefirebase::admob::BannerView::PresentationState enumerated type andOnPresentationStateChanged listener method are not included in the newGoogle Mobile Ads C++ SDK.
The following are alternative ways to detect presentation state changes in thelife cycle of anAdView:
firebase::admob::BannerView::Listener OnPresentationStateChanged event | firebase::gma::AdListener counterpart |
|---|---|
kPresentationStateHidden | WhenAdListener::OnAdClosed is invoked, or whenAdView::Hide() completes its asynchronous operation successfully |
kPresentationStateVisibleWithoutAd | None. Attempting to invokeAdView::Show() an unloadedAdView will result in an error. |
kPresentationStateVisibleWithAd | WhenAdListener::OnAdOpened is invoked, or whenAdView::Show() completes its asynchronous operation successfully with an ad |
kPresentationStateOpenedPartialOverlay | Query the bounding box afterAdListener::OnAdOpened() has been invoked to determine the size and position of the ad being shown. Alternatively, query theAdView's position andAdSize and/or monitor the bounding box viaAdViewBoundingBoxListener. |
kPresentationStateCoveringUI | SeekPresentationStateOpenedPartialOverlay above |
RewardedAd is now a class
The deprecated Firebase AdMob C++ SDK facilitated rewarded ads viaa collection of functions in thefirebase::admob::rewarded_ad namespace. Thesefunctions have been coalesced into a newRewardedAd class which servesads with a similar API surface toInterstitialAd (see next section).
InterstitialAd andRewardedAd listeners
Both interstitial ads and rewarded ads are considered full screen ads. A newFullScreenContentListener can be installed to listen to advertisement lifecycle events for these ad types, and a separatePaidEventListener can beinstalled to track when theAdMob service has deemed a paid event hasoccurred.
RewardedAd has an additional listener to monitor user-earned reward events.
New full screen ad callback methods
FullScreenContentListener methods | PaidEventListener methods | UserEarnedRewardListener methods |
|---|---|---|
OnAdClicked | OnPaidEvent | OnUserEarnedReward |
OnAdDismissedFullScreenContent | ||
OnAdFailedToShowFullScreenContent | ||
OnAdImpression | ||
OnAdShowedFullScreenContent |
Methods changed/removed/replaced
The table below lists the specific methods changed in the newGoogle Mobile Ads C++ SDK. Methods with parameters listed remain but theirsignatures have changed.
| Class | Firebase AdMob C++ SDK API | Google Mobile Ads C++ SDK API | Notes |
|---|---|---|---|
BannerView | MoveTo | AdView::SetPosition | |
presentation_state | Removed | Handled byAdViewListener events andAdView::Show andAdView::Hide future results. | |
SetListener | AdView::SetAdListenerAdView::SetBoundingBoxListenerAdView::SetPaidEventListener | The new listener design increases the fidelity of detectingAdView lifecycle events. | |
Listener::OnPresentationStateChanged | Removed | SeeBannerView::SetListener, above. | |
Listener::OnBoundingBoxChanged | AdViewBoundingBoxListener::OnBoundingBoxChanged | ||
| InterstitialAd | Initialize(AdParent parent, const char* ad_unit_id) | Initialize(AdParent parent) | Thead_unit_id parameter is now part of theLoadAd operation. |
LoadAd(const AdRequest& request) | LoadAd(const char* ad_unit_id, const AdRequest& request) | ||
presentation_state | Removed | Thepresentation_state enumeration has been removed. UseFullScreenContentListener. | |
SetListener | SetFullScreenContentListenerSetPaidEventListener | ||
Destroy | Removed | Cleaning up resources is now part of theRewardedAd destructor. | |
RewardedAd(formally RewardedVideoAd) | Initialize | Initialize(AdParent parent) | AdParent was previously passed toShow, but is now part of initialization. |
presentation_state | Removed | Thepresentation_state enumeration has been removed. UseFullScreenContentListener. | |
SetListener | SetFullScreenContentListenerSetPaidEventListenerShow | AUserEarnedReward listener is also defined when showing aRewardedAd. See below. | |
Show(AdParent parent) | Show(UserEarnedRewardListener* listener) |
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-17 UTC.