How to Implement the Google Mobile Ads SDK in Android and iOS Apps
TLDR: The Google Mobile Ads SDK integrates via a four-step workflow: add the platform-specific dependency, configure your AdMob App ID, initialize the SDK on a background thread, and verify the build compiles without errors.
The Google Mobile Ads (GMA) SDK enables Android, iOS, and Unity applications to monetize through AdMob or Google Ad Manager. According to the google/skills repository, the integration architecture follows a consistent pattern across platforms—adding dependencies, setting the application identifier, initializing the SDK, and verifying the build—though implementation details differ between Gradle-based Android projects and Swift Package Manager-based iOS projects.
Step 1: Add the SDK Dependency
The SDK uses "up-to-next-major" versioning to ensure forward compatibility while pulling the most recent stable release.
Android Gradle Configuration
For Android applications, add the com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk dependency to your app-level build.gradle file. As documented in skills/ads/google-mobile-ads-get-started/references/android-get-started.md, the latest version is available through Maven Central.
dependencies {
// Add the latest GMA SDK version
implementation "com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:<latest-version>"
}
iOS Swift Package Manager Setup
For iOS applications, add the Google Mobile Ads Swift Package using the repository URL https://github.com/googleads/swift-package-manager-google-mobile-ads.git. This process is detailed in skills/ads/google-mobile-ads-get-started/references/ios-get-started.md. For automated CI/CD pipelines, you can also use Ruby-based xcodeproj automation to programmatically add the package dependency.
Step 2: Configure the Application Identifier
Both platforms require your unique AdMob App ID, though configuration methods differ. Use the provided test IDs during development to avoid generating invalid traffic.
Android App ID Configuration
In Android, provide your App ID through InitializationConfig.Builder. The sample test ID is ca-app-pub-3940256099942544~3347511713 as specified in skills/ads/google-mobile-ads-get-started/references/android-get-started.md.
val config = InitializationConfig.Builder("ca-app-pub-3940256099942544~3347511713")
.build()
iOS Info.plist Configuration
In iOS, add the GADApplicationIdentifier key to your Info.plist file. The corresponding sample test ID is ca-app-pub-3940256099942544~1458002511.
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
Additionally, iOS 14+ requires SKAdNetwork identifiers for proper attribution. Include the identifiers listed in skills/ads/google-mobile-ads-get-started/assets/skadnetwork-identifiers.xml to enable ad attribution on iOS 14 and above.
Step 3: Initialize the Mobile Ads SDK
Initialization must occur off the main thread to prevent UI stalls during app startup.
Android Initialization
Call MobileAds.initialize() on a background thread, passing your InitializationConfig and an initialization listener. As implemented in the Android reference guide, this ensures the SDK prepares ad resources without blocking the UI.
MobileAds.initialize(context, config) { status ->
// SDK initialization complete
}
iOS Initialization
In Swift, execute MobileAds.shared.start() at your application's entry point, such as in AppDelegate.swift or the @main app struct for SwiftUI applications.
import GoogleMobileAds
func initialiseGMA() {
MobileAds.shared.start { status in
print("SDK initialized.")
}
}
Step 4: Verify Your Integration
Confirm the SDK is properly linked by building your project and resolving any compile-time errors.
For Android, run the Gradle assemble command as documented in skills/ads/google-mobile-ads-get-started/references/android-get-started.md:
./gradlew assembleDebug
For iOS, build via Xcode or use the command line tool:
xcodebuild
Successful compilation indicates the SDK is ready for ad format integration (banner, interstitial, or rewarded ads). The complete high-level workflow is summarized in skills/ads/google-mobile-ads-get-started/SKILL.md.
Summary
- Dependency Management: Android uses Maven/Gradle with
com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk, while iOS uses Swift Package Manager fromhttps://github.com/googleads/swift-package-manager-google-mobile-ads.git. - App ID Configuration: Android uses
InitializationConfig.Builderwith your AdMob App ID, while iOS uses theGADApplicationIdentifierkey inInfo.plist. - Threading Requirements: Always initialize the SDK on a background thread to avoid Application Not Responding (ANR) errors on Android or UI freezes on iOS.
- iOS Attribution: iOS 14+ requires SKAdNetwork identifiers from
skills/ads/google-mobile-ads-get-started/assets/skadnetwork-identifiers.xmlfor proper conversion tracking. - Build Verification: Use
./gradlew assembleDebugfor Android andxcodebuildfor iOS to validate the integration before deploying ad units.
Frequently Asked Questions
What is the difference between Android and iOS SDK initialization?
Android requires explicitly passing an InitializationConfig object containing your App ID to MobileAds.initialize(), while iOS automatically reads the App ID from Info.plist and only requires calling MobileAds.shared.start(). Both methods accept completion handlers to confirm initialization status and report adapter readiness.
Why does iOS require SKAdNetwork identifiers?
iOS 14.5+ privacy changes require SKAdNetwork identifiers to attribute ad conversions without relying on the Identifier for Advertisers (IDFA). The Google Mobile Ads SDK requires these identifiers, found in skills/ads/google-mobile-ads-get-started/assets/skadnetwork-identifiers.xml, to properly track campaign performance and enable ad attribution on Apple devices.
Can I initialize the Google Mobile Ads SDK on the main thread?
No, SDK initialization should occur on a background thread to prevent UI stalls and Application Not Responding (ANR) errors. The Android MobileAds.initialize(context, InitializationConfig, listener) method and iOS MobileAds.shared.start() completion handlers are designed to operate asynchronously off the main thread.
Where do I find the latest SDK version for Android?
The latest version is available through Maven Central metadata endpoints. As documented in skills/ads/google-mobile-ads-get-started/references/android-get-started.md, you can check the Maven repository for the current release number or use the metadata API to dynamically retrieve the latest stable version when configuring your build.gradle dependencies.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →