Google Mobile Ads Android Next-Gen Migration

Google Mobile Ads Android Next-Gen Migration

Guides an AI agent migrating an Android app from the legacy Google Mobile Ads SDK to the Next-Gen SDK using mapping tables and a checklist.

Skill files1 file
SKILL.md197 lines
1
---
2
name: google-mobile-ads-android-migrate-to-next-gen
3
description: Migrates Android applications from the old, legacy Google Mobile
4
Ads (GMA) SDK (com.google.android.gms:play-services-ads) to the new GMA
5
Next-Gen SDK (com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk).
6
Provides comprehensive mapping tables for imports, classes, and method
7
signatures to help determine migration steps. Use when migrating an existing
8
Android codebase from the old, legacy GMA SDK to GMA Next-Gen SDK.
9
metadata:
10
version: "1.1.0"
11
category: GoogleAds
12
---
13
# AI Migration Agent Instructions for the Google Mobile Ads SDK
14
15
## Migration Workflow
16
17
Use this checklist to track your migration progress:
18
19
* **Configure Gradle**:
20
- [ ] Replace `com.google.android.gms:play-services-ads` with the latest
21
stable version of
22
`com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk`. If you
23
cannot access Maven directly, run the following command to fetch the
24
latest version. The version returned in the `latest` tag is the latest
25
version of the GMA Next-Gen SDK:
26
27
```bash
28
curl -sS https://dl.google.com/dl/android/maven2/com/google/android/libraries/ads/mobile/sdk/ads-mobile-sdk/maven-metadata.xml | sed -n 's/.*<latest>\(.*\)<\/latest>.*/\1/p'
29
```
30
31
- [ ] Update `minSdk` (24+) and `compileSdk` (34+).
32
- [ ] Exclude `play-services-ads` and `play-services-ads-lite` from all
33
dependencies globally in the app-level build file to avoid duplicate
34
symbol errors.
35
- [ ] Sync Gradle before moving on to the next step.
36
* **Per-File Migration**:
37
- [ ] Refactor the codebase following the API Mapping and Method Mapping
38
tables to migrate imports, class names, and method signature to GMA
39
Next-Gen SDK.
40
* **Verify and Build**:
41
- [ ] Run `gradle build -x test` to confirm a successful clean build.
42
Resolve any GMA SDK related compile errors.
43
44
## Core Migration Rules
45
46
* **App ID Usage**: **Always** use the value of the
47
`com.google.android.gms.ads.APPLICATION_ID` meta-data tag from
48
`AndroidManifest.xml` for the `applicationId` in `InitializationConfig`.
49
* *Constraint*: Preserve the `<meta-data>` tag in the manifest; it is
50
still required for publishers using the User Messaging Platform SDK.
51
* **Initialization Sequence**:
52
1. Call `MobileAds.initialize()` on a background thread.
53
2. Ensure `initialize()` is called **before** any other SDK methods.
54
3. If using `RequestConfiguration`, bundle it into
55
`InitializationConfig.Builder.setRequestConfiguration()`. **Do not**
56
call `MobileAds.setRequestConfiguration()` before initialization.
57
* **UI Threading**: **MANDATORY**: Callbacks in GMA-Next Gen SDK are invoked
58
on a background thread. **ALL UI-RELATED OPERATIONS** (e.g., Toasts, View
59
updates, Fragment transactions) **MUST** be wrapped in `runOnUiThread {}` or
60
`Dispatchers.Main.launch {}` within GMA SDK callbacks. SKIPPING THIS STEP
61
WILL CAUSE THE APPLICATION TO CRASH.
62
* **Mediation**: Classes implementing
63
`com.google.android.gms.ads.mediation.Adapter` MUST continue using
64
`com.google.android.gms.ads`.
65
66
## Format Specifics
67
68
### Banner Ads
69
70
* Use `com.google.android.libraries.ads.mobile.sdk.banner.AdView` for loading
71
GMA Next-Gen SDK banners.
72
* The following API checks if a banner is collapsible:
73
`adView.getBannerAd().isCollapsible()`.
74
75
### Native Ads
76
77
* **NativeAdLoader**: `NativeAdLoader` is abstract and cannot be instantiated.
78
It is used statically (e.g., `NativeAdLoader.load(...)`).
79
* The following APIs are now set on the `NativeAdRequest.Builder`:
80
* `.setCustomFormatIds(customFormatIds: List<String>)`
81
* `.disableImageDownloading()`
82
* `.setMediaAspectRatio(mediaAspectRatio: NativeMediaAspectRatio)`
83
* `.setAdChoicesPlacement(adChoicesPlacement: AdChoicesPlacement)`
84
* `.setVideoOptions(videoOptions: VideoOptions)`
85
* **Removal**: Delete all "Mute This Ad" logic; it is unsupported in GMA
86
Next-Gen SDK.
87
* **MediaView**: `NativeAd` no longer has a direct `mediaView` variable; use
88
`registerNativeAd(nativeAd, mediaView)` to associate the ad with the view.
89
90
### Ad preloading
91
92
* Unless specified in the mapping table, ad preloading methods in the GMA
93
Next-Gen SDK retain the same API signatures and parameters as the Old SDK.
94
95
## API Mapping
96
97
This table covers the main classes and their GMA Next-Gen SDK equivalents.
98
99
| Feature | Old SDK Import (`com.google.android.gms.ads...`) | GMA Next-Gen SDK Import (`com.google.android.libraries.ads.mobile.sdk...` ) |
100
|:---------------------------|:-------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
101
| **Core** | | |
102
| Initialization | `MobileAds` | `MobileAds`, `initialization.InitializationConfig` |
103
| Initialization Listener | `initialization.OnInitializationCompleteListener` | `initialization.OnAdapterInitializationCompleteListener` |
104
| Ad Request | `AdRequest` | *Format specific* (e.g. `common.AdRequest`, `banner.BannerAdRequest`, `nativead.NativeAdRequest`) (Ad Unit ID is declared in `Builder`. Load() no longer takes an activity) |
105
| Load Error | `LoadAdError` | `common.LoadAdError` (`LoadAdError` no longer has a domain variable. REMOVE the domain variable if found.) |
106
| Full Screen Show Error | `AdError` (within `FullScreenContentCallback`) | `common.FullScreenContentError` (within format-specific `AdEventCallback`) |
107
| Request Configuration | `RequestConfiguration` | `common.RequestConfiguration` (Nested Enums/Constants for RequestConfiguration are now under common.RequestConfiguration.) |
108
| Event Callbacks | `FullScreenContentCallback` (for full screen formats), `AdListener` (Banner, Native) | *Format Specific* (e.g., `interstitial.InterstitialAdEventCallback`, `banner.BannerAdEventCallback`, `native.NativeAdEventCallback`). Variable on the ad format is `adEventCallback`. |
109
| **Tools** | | |
110
| Ad Inspector | `MobileAds.openAdInspector()` | `MobileAds.openAdInspector()` (`openAdInspector` no longer takes an activity) |
111
| Ad Inspector Listener | `OnAdInspectorClosedListener` | `common.OnAdInspectorClosedListener` |
112
| **Formats** | | |
113
| App Open | `appopen.AppOpenAd` | `appopen.AppOpenAd` |
114
| App Open Load | `appopen.AppOpenAd.AppOpenAdLoadCallback` | `common.AdLoadCallback<appopen.AppOpenAd>` |
115
| Banner | `AdView`, `AdSize` | `banner.AdView`, `banner.AdSize` (`AdView` no longer has `pause()`, `resume()`, `setAdSize()`). `AdSize` is declared in `BannerAdRequest`. |
116
| Banner Load | `AdListener` | `common.AdLoadCallback<banner.BannerAd>` |
117
| Banner Events | `AdListener` | `banner.BannerAdEventCallback`, `banner.BannerAdRefreshCallback` |
118
| Interstitial | `interstitial.InterstitialAd` | `interstitial.InterstitialAd` |
119
| Interstitial Load | `interstitial.InterstitialAd.InterstitialAdLoadCallback` | `common.AdLoadCallback<interstitial.InterstitialAd>` |
120
| Ad Loader | `AdLoader` | `nativead.NativeAdLoader` |
121
| Native | `nativead.NativeAd` | `nativead.NativeAd` (No longer has a `mediaView` variable) |
122
| Native Custom Format Ad | `nativead.NativeCustomFormatAd` | `nativead.CustomNativeAd` |
123
| Native Custom Click | `nativead.NativeCustomFormatAd.OnCustomClickListener` | `nativead.OnCustomClickListener` (set on the `CustomNativeAd` object (e.g., `.onCustomClickListener`) |
124
| Native Load | `nativead.NativeAd.OnNativeAdLoadedListener` | `nativead.NativeAdLoaderCallback` |
125
| Native Ad View | `nativead.NativeAdView` | `nativead.NativeAdView` |
126
| Media Content | `MediaContent` | `nativead.MediaContent` (hasVideoContent is declared as a `val`) |
127
| Media Aspect Ratio | `MediaAspectRatio` | `nativead.MediaAspectRatio` |
128
| Video Options | `VideoOptions` | `common.VideoOptions` |
129
| Video Controller | `VideoController` | `common.VideoController` (VideoLifecycleCallbacks is now an interface, so instantiate with `object : VideoController.VideoLifecycleCallbacks { ... }`) |
130
| Rewarded | `rewarded.RewardedAd` | `rewarded.RewardedAd` |
131
| Rewarded Load | `rewarded.RewardedAd.RewardedAdLoadCallback` | `common.AdLoadCallback<rewarded.RewardedAd>` |
132
| Rewarded Interstitial | `rewardedinterstitial.RewardedInterstitialAd` | `rewardedinterstitial.RewardedInterstitialAd` |
133
| Rewarded Interstitial Load | `rewardedinterstitial.RewardedInterstitialAd.RewardedInterstitialAdLoadCallback` | `common.AdLoadCallback<rewardedinterstitial.RewardedInterstitialAd>` |
134
| Paid Event Listener | `OnPaidEventListener` | `common.AdEventCallback` |
135
| Response Info | `ResponseInfo` | `common.ResponseInfo` |
136
| Adapter Response Info | `AdapterResponseInfo` | `common.AdSourceResponseInfo` |
137
| **Rewards** | | |
138
| Reward Listener | `OnUserEarnedRewardListener` | `rewarded.OnUserEarnedRewardListener` |
139
| Reward Item | `rewarded.RewardItem` | `rewarded.RewardItem` (property access on `RewardedAd` and `RewardedInterstitialAd` is now `getRewardItem()`) |
140
| Ad Value | `AdValue` | `common.AdValue` |
141
| **Preloading** | | |
142
| Configuration | `preload.PreloadConfiguration` | `common.PreloadConfiguration` |
143
| Callback | `preload.PreloadCallbackV2` | `common.PreloadCallback` (Now an interface instead of an abstract class) |
144
| Interstitial Preloader | `interstitial.InterstitialPreloader` | `interstitial.InterstitialAdPreloader` |
145
| **Ad Manager** | | |
146
| Ad Request | `admanager.AdManagerAdRequest` | `common.AdRequest` (Now directly implemented in the `AdRequest` class) |
147
| Ad View | `admanager.AdView` | `banner.AdView` (No `AdManagerAdView` class) |
148
| App Event Listener | `admanager.AppEventListener` | `common.OnAppEventListener` |
149
150
## Method Mapping
151
152
This table covers the main methods and their GMA Next-Gen SDK equivalents.
153
154
| Feature | Old SDK Method Signature | GMA Next-Gen SDK Method Signature |
155
|:-----------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
156
| **Core** | | |
157
| MobileAds Initialization | `MobileAds.initialize(Context context, OnInitializationCompleteListener listener)` | `MobileAds.initialize(Context context, InitializationConfig config, OnInitializationCompleteListener listener)` |
158
| InitializationConfig Builder | N/A | `InitializationConfig.Builder(String applicationId)` |
159
| Ad Request Builder | `AdRequest.Builder().build()` | `AdRequest.Builder(String adUnitId).build()` (for App Open, Interstitial, Rewarded, Rewarded Interstitial) **Banner:** `BannerAdRequest.Builder(String adUnitId, AdSize adSize).build()` **Native:** `NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>).build()` |
160
| Add Network Extras (AdMobAdapter) | `AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)` | `AdRequest.Builder(String adUnitId).setGoogleExtrasBundle(Bundle extraBundle)` |
161
| Add Network Extras (Ad Source Adapter) | `AdRequest.Builder().addNetworkExtrasBundle(Class<MediationExtrasReceiver>, Bundle networkExtras)` | `AdRequest.Builder(String adUnitId).putAdSourceExtrasBundle(Class<MediationExtrasReceiver> adapterClass, Bundle adSourceExtras)` |
162
| Custom Targeting | `AdRequest.Builder().setCustomTargeting(String key, String value)` | `AdRequest.Builder(String adUnitId).putCustomTargeting(String key, String value)` |
163
| **Formats** | | |
164
| App Open | `AppOpenAd.load(Context context, String adUnitId, AdRequest request, AppOpenAdLoadCallback loadCallback)` | `AppOpenAd.load(AdRequest request, AdLoadCallback<AppOpenAd> loadCallback)` |
165
| Banner | `AdView.loadAd(AdRequest request)` | `AdView.loadAd(BannerAdRequest request, AdLoadCallback<BannerAd> loadCallback)` |
166
| Interstitial | `InterstitialAd.load(Context context, String adUnitId, AdRequest request, InterstitialAdLoadCallback loadCallback)` | `InterstitialAd.load(AdRequest request, AdLoadCallback<InterstitialAd> loadCallback)` |
167
| Rewarded | `RewardedAd.load(Context context, String adUnitId, AdRequest request, RewardedAdLoadCallback loadCallback)` | `RewardedAd.load(AdRequest request, AdLoadCallback<RewardedAd> loadCallback)` |
168
| Rewarded Interstitial | `RewardedInterstitialAd.load(Context context, String adUnitId, AdRequest request, RewardedInterstitialAdLoadCallback loadCallback)` | `RewardedInterstitialAd.load(AdRequest request, AdLoadCallback<RewardedInterstitialAd> loadCallback)` |
169
| Native Builder | `AdLoader.Builder(Context context, String adUnitId).forNativeAd(NativeAd.OnNativeAdLoadedListener onNativeAdLoadedListener)` | `NativeAdRequest.Builder(String adUnitId, nativeAdTypes: List<NativeAdType>)` (Include `NativeAd.NativeAdType.NATIVE` in `nativeAdTypes`) |
170
| Native Load | `AdLoader.Builder(...).build().loadAd(AdRequest request)` | `NativeAdLoader.load(NativeAdRequest request, NativeAdLoaderCallback callback)` |
171
| Native Ad Register | `NativeAdView.setNativeAd(NativeAd nativeAd)` | `NativeAdView.registerNativeAd(NativeAd nativeAd, mediaView: MediaView?)` |
172
| Set an App Event Listener (Banner) | `AdManagerAdView.appEventListener` | `BannerAd.adEventCallback` (`onAppEvent(name: String, data: String?)` is now part of the `BannerAdEventCallback`) |
173
| Set an App Event Listener (Interstitial) | `AdManagerInterstitialAd.appEventListener` | `InterstitialAd.adEventCallback` (`onAppEvent(name: String, data: String?)` is now part of the `InterstitialAdEventCallback`) |
174
| **Callbacks** | | |
175
| onAdOpened | `AdListener.onAdOpened()` | `AdEventCallback.onAdShowedFullScreenContent()` |
176
| onAdClosed | `AdListener.onAdClosed()` | `AdEventCallback.onAdDismissedFullScreenContent()` |
177
| onFailedToShowFullScreenContent | `onAdFailedToShowFullScreenContent(adError: AdError)` | `onAdFailedToShowFullScreenContent(fullScreenContentError: FullScreenContentError)` |
178
| onAdLoaded | **AdLoadCallback**: `onAdLoaded(ad: T)` (e.g., `InterstitialAdLoadCallback`, `RewardedAdLoadCallback`, `RewardedInterstitialAdLoadCallback`) | Parameter name is always `ad` **Format specific**: `onAdLoaded(ad: InterstitialAd)`, `onAdLoaded(ad: RewardedAd)`, `onAdLoaded(ad: RewardedInterstitialAd)` |
179
| onAdFailedToLoad | `onAdFailedToLoad(loadAdError: LoadAdError)` | `onAdFailedToLoad(adError: LoadAdError)` |
180
| onCustomFormatAdLoaded | `OnCustomFormatAdLoadedListener.onCustomFormatAdLoaded(NativeCustomFormatAd ad)` | `NativeAdLoaderCallback.onCustomNativeAdLoaded(CustomNativeAd customNativeAd)` |
181
| onPaidEventListener | `OnPaidEventListener.onPaidEvent(AdValue value)` | `AdEventCallback.onAdPaid(value: AdValue)` (Format-specific e.g., `banner.BannerAdEventCallback.onAdPaid(value: AdValue)`) |
182
| onVideoMute | `onVideoMute(muted: Boolean)` | `onVideoMute(isMuted: Boolean)` |
183
| onAdPreloaded | `onAdPreloaded(preloadId: String, responseInfo: ResponseInfo?)` | `onAdPreloaded(preloadId: String, responseInfo: ResponseInfo)` |
184
| **Preloading** | | |
185
| Configuration | `PreloadConfiguration.Builder(String adUnitId).build()` | `PreloadConfiguration(AdRequest request)` |
186
| **Response Info** | | |
187
| Get Response Info | `ad.responseInfo` | `ad.getResponseInfo()` |
188
| Loaded Adapter Responses Info | `responseInfo.getLoadedAdapterResponseInfo()` | `responseInfo.loadedAdSourceResponseInfo` |
189
| Get Adapter Responses | `responseInfo.getAdapterResponses()` | `responseInfo.adSourceResponses` |
190
| Get Mediation Adapter Class | `responseInfo.getMediationAdapterClassName()` | `responseInfo.adapterClassName` |
191
| **Adapter Response Info** | | |
192
| Ad Source ID | `AdapterResponseInfo.getAdSourceId()` | `AdSourceResponseInfo.id` |
193
| Ad Source Name | `AdapterResponseInfo.getAdSourceName()` | `AdSourceResponseInfo.name` |
194
| Ad Source Instance ID | `AdapterResponseInfo.getAdSourceInstanceId()` | `AdSourceResponseInfo.instanceId` |
195
| Ad Source Instance Name | `AdapterResponseInfo.getAdSourceInstanceName()` | `AdSourceResponseInfo.instanceName` |
196
197

© Google LLC · Apache 2.0 · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 13,233 prompts

More by @OpenSourceBuffGuy

See all
Jungle explorer in four labeled storyboard shots prompt image

Jungle explorer in four labeled storyboard shots

Draws a four-panel cinematic storyboard of the same jungle explorer in different camera shots, each with a bold shot label, in golden jungle light.

image-prompt, storyboard, multi-panel, cinematic, photorealistic, forest, woman, close-up, low-angle, high-angle, wide-shot, dramatic-lighting, golden-hour, text-rendering, negative-prompt, widescreen, gpt-image, character-consistency, for-filmmakers, moody, structured-output, medium-shot, bokeh, long-form

Credit Score Improver prompt image

Credit Score Improver

Builds a credit score improvement plan: factor analysis, ranked actions, dispute strategy for errors, utilisation targets and a realistic timeline.

system-prompt, act-as, personal-finance, debt-payoff, financial-planning, planner, expert-advice, consumer-rights, united-states, table, roadmap, action-items, structured-output, xml-tags, guardrails, beginner-friendly, prioritization, timeline, step-by-step-guide, calculator

Grilled Chicken Taco Product Photo prompt image

Grilled Chicken Taco Product Photo

Photographs a grilled chicken taco with char marks, red cabbage, creamy sauce and fresh garnish on a pure white background in clean food-photography style.

image-prompt, nano-banana, food-photography, product-photography, photorealistic, white-background, minimalist, still-life, close-up, soft-lighting, natural-light, studio-lighting, cooking, quick, for-photographers, for-small-business-owners

Reviews

Loading reviews…

Discussion

Loading comments…