Migrate to the new Google Mobile Ads C++ SDK

DEPRECATED: The Google Mobile Ads C++ SDK isdeprecated as of June 17, 2024 and should not be adopted in projects that don't already use it. It will enterEnd-of-Maintenance (EoM) on June 17, 2025. Note that versions of the SDK released before the EoM date will continue to function, but no further bug fixes or changes will be released after the EoM date.

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++ SDKNew Google Mobile Ads C++ SDK
include/firebase/admobinclude/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++ SDKNew Google Mobile Ads C++ SDK
firebase_admob.xcframeworkfirebase_gma.xcframework

Android

Deprecated Firebase AdMob C++ SDKNew Google Mobile Ads C++ SDK
libfirebase_admob.alibfirebase_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:

  • BannerView is renamed toAdView.
  • NativeAdExpressView is removed.
  • TheRewardedVideo namespace is replaced with aRewardedAd class.
  • ThePresentationState enumeration and listeners are removed andreplaced withAdListener andFullScreenContent listeners.
  • The following parameters are removed as per-ad configuration parametersinAdRequests:

    • the configuration of test device IDs
    • the targeting of advertisements based on age

    Instead, these parameters can now be configured inRequestConfigurationwhich is a global setting that will affect all subsequent ad loads.

Deprecatedfirebase::admob namespaceNewfirebase::gma namespace
AdSizeType (enum)AdSize::Type (enum)
BannerViewAdView
BannerView::ListenerAdListener
AdViewBoundingBoxListener
PaidEventListener
BannerView::PositionAdView::Position
BannerView::PresentationStateRemoved
ChildDirectedTreatmentStateRequestConfiguration::TagForChildDirectedTreatment
Gender (enum)Removed
InterstitialAd::ListenerFullScreenContentListener
PaidEventListener
KeyValuePairRemoved
NativeExpressAdViewRemoved
PollableRewardListenerRemoved
RewardItemAdReward
RewardedVideoAd (namespace)RewardedAd (class)
RewardedVideoAd::ListenerFullScreenContentListener
PaidEventListener
UserEarnedRewardListener
AdMobError (enum)AdErrorCode (enum)
RewardItemAdReward

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 afirebase::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::kLargeBannerTaller version ofkBanner, typically 320x100

AdSize::kLeaderboard

Interactive Advertising Bureau (IAB) leaderboard ad size (728x90 density-independent pixels)
AdSize::kMediumRectangleInteractive Advertising Bureau (IAB) medium rectangle ad size (300x250 density-independent pixels)
Static methods infirebase::gma::AdSize to help construct instances ofAdSize
GetLandscapeAnchoredAdaptiveBannerAdSizeCreates anAdSize with the given width and a Google-optimized height to create a banner ad in landscape mode
GetPortraitAnchoredAdaptiveBannerAdSizeCreates anAdSize with the given width and a Google-optimized height to create a banner ad in portrait mode
GetCurrentOrientationAnchoredAdaptiveBannerAdSizeCreates anAdSize with the given width and a Google-optimized height to create a banner ad given the current orientation
GetInlineAdaptiveBannerAdSizeCreates anAdSize most suitable for banner ads given a maximum height

ThisAdSize allows Google servers to choose an optimal ad size with a height less than or equal to a specified max height.

GetLandscapeInlineAdaptiveBannerAdSizeCreates anInlineAdaptiveAdSize with the given width and the device's landscape height
GetPortraitInlineAdaptiveBannerAdSizeCreates anInlineAdaptiveAdSize with the given width and the device's portrait height.
GetCurrentOrientationInlineAdaptiveBannerAdSizeA 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:

  • AdListener tracks ad lifecycle and user interaction events.
  • AdViewBoundingBoxListener is invoked when theAdView is 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 eventfirebase::gma::AdListener counterpart
kPresentationStateHiddenWhenAdListener::OnAdClosed is invoked, or whenAdView::Hide() completes its asynchronous operation successfully
kPresentationStateVisibleWithoutAdNone. Attempting to invokeAdView::Show() an unloadedAdView will result in an error.
kPresentationStateVisibleWithAdWhenAdListener::OnAdOpened is invoked, or whenAdView::Show() completes its asynchronous operation successfully with an ad
kPresentationStateOpenedPartialOverlayQuery 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.
kPresentationStateCoveringUISeekPresentationStateOpenedPartialOverlay 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 methodsPaidEventListener methodsUserEarnedRewardListener methods
OnAdClickedOnPaidEventOnUserEarnedReward
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.

ClassFirebase AdMob C++ SDK APIGoogle Mobile Ads C++ SDK APINotes
BannerViewMoveToAdView::SetPosition
presentation_stateRemovedHandled byAdViewListener events andAdView::Show andAdView::Hide future results.
SetListenerAdView::SetAdListener
AdView::SetBoundingBoxListener
AdView::SetPaidEventListener
The new listener design increases the fidelity of detectingAdView lifecycle events.
Listener::OnPresentationStateChangedRemovedSeeBannerView::SetListener, above.
Listener::OnBoundingBoxChangedAdViewBoundingBoxListener::OnBoundingBoxChanged
InterstitialAdInitialize(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_stateRemovedThepresentation_state enumeration has been removed. UseFullScreenContentListener.
SetListenerSetFullScreenContentListener
SetPaidEventListener
DestroyRemovedCleaning up resources is now part of theRewardedAd destructor.
RewardedAd
(formally
RewardedVideoAd)
InitializeInitialize(AdParent parent)AdParent was previously passed toShow, but is now part of initialization.
presentation_stateRemovedThepresentation_state enumeration has been removed. UseFullScreenContentListener.
SetListenerSetFullScreenContentListener
SetPaidEventListenerShow
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.