Google Mobile Ads SDK — Migration to GMA Next-Gen
Provides comprehensive mapping tables for migrating Android applications from the legacy com.google.android.gms:play-services-ads SDK to the new com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk.
Migration Workflow
- Configure Gradle: Replace dependency, update
minSdk(24+) andcompileSdk(34+) - Per-file migration: Refactor imports, class names, and method signatures
- Verify and build: Run
gradle build -x testto confirm clean build
Code Example: Gradle Dependency
// Old (legacy)
// implementation("com.google.android.gms:play-services-ads:23.0.0")
// New (Next-Gen)
implementation("com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:LATEST_VERSION")
Key Migration Rules
- App ID: Preserve
com.google.android.gms.ads.APPLICATION_IDmeta-data in manifest - UI Threading: Callbacks invoke on background thread — wrap UI operations in
runOnUiThread{} - Initialization: Call
MobileAds.initialize()on background thread; bundleRequestConfigurationintoInitializationConfig - Banner ads: Use
com.google.android.libraries.ads.mobile.sdk.banner.AdView - Response info: Use
ad.getResponseInfo()(not.responseInfo)
Common Pitfalls
- Missing dependency exclusion: Exclude
play-services-adsandplay-services-ads-liteglobally to avoid duplicate symbol errors - UI thread crashes: All UI operations in GMA callbacks MUST use
runOnUiThread{}orDispatchers.Main - AdSize mismatch: AdSize is now declared in
BannerAdRequest, not onAdView - MediaView removed: Use
registerNativeAd(nativeAd, mediaView)instead ofnativeAd.mediaView
Verification Checklist
- Gradle dependency updated to
ads-mobile-sdk -
minSdk>= 24,compileSdk>= 34 - Legacy SDK excluded from all transitive dependencies
- Build succeeds:
gradle build -x test - All imports refactored per API mapping table