How to Integrate Google Mobile Ads SDK: Complete Integration Guide for Android, iOS, and Unity
Integrate the Google Mobile Ads (GMA) SDK by adding the platform-specific dependency, configuring your AdMob App ID, initializing the MobileAds class once at startup, and verifying with a test build.
The Google Mobile Ads SDK enables Android, iOS, and Unity applications to serve AdMob and Google Ad Manager advertisements. This guide walks through the complete integration workflow based on the official google/skills repository, covering dependency setup, initialization patterns, and verification steps for each platform.
Core Integration Workflow
According to skills/ads/google-mobile-ads-get-started/SKILL.md, GMA SDK integration follows a four-step pattern that remains consistent across platforms, with only implementation details changing:
| Step | Action | Purpose |
|---|---|---|
| 1 | Add SDK dependency | Pulls the library into your build system |
| 2 | Set application identifier | Links your app to your AdMob account |
| 3 | Initialize the SDK | Prepares ad-loading components and validates configuration |
| 4 | Verify the integration | Confirms correct setup before production release |
Step 1: Add the Google Mobile Ads SDK Dependency
Each platform uses a different distribution mechanism. Install the correct package for your target environment.
Android (Gradle)
Add the Maven artifact to your app/build.gradle:
implementation "com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:<latest>"
The google/skills repository recommends fetching the latest stable version at runtime via Maven metadata rather than hard-coding a version number. See references/android-get-started.md for version resolution scripts.
iOS (Swift Package Manager)
In Xcode, add the Swift package with URL:
https://github.com/googleads/swift-package-manager-google-mobile-ads.git
As documented in references/ios-get-started.md, this pulls the GoogleMobileAds framework with automatic dependency resolution.
Unity (Package Manager)
Use the identical Git URL in Unity's Package Manager window. The GoogleMobileAds Unity package wraps native Android and iOS implementations with a unified C# API.
Step 2: Configure Your AdMob Application ID
The SDK requires a valid AdMob App ID to initialize. Each platform stores this identifier differently.
Android: Create an InitializationConfig object programmatically:
val config = InitializationConfig.Builder("ca-app-pub-3940256099942544~3347511713")
.build()
iOS: Add GADApplicationIdentifier to Info.plist:
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
Also include the SKAdNetwork identifiers from assets/skadnetwork-identifiers.xml for App Store compliance.
Unity: Enter the App ID in the GoogleMobileAdsSettings inspector, or set it via script before initialization.
Step 3: Initialize the Google Mobile Ads SDK
Critical requirement: Initialize the SDK exactly once per app launch. The initialization process validates your App ID, contacts Google servers, and prepares internal ad-loading components.
Android Initialization (Kotlin)
import com.google.android.libraries.ads.mobile.sdk.MobileAds
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig
import com.google.android.libraries.ads.mobile.sdk.initialization.OnAdapterInitializationCompleteListener
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationStatus
fun initializeGma(context: Context) {
val config = InitializationConfig.Builder("ca-app-pub-3940256099942544~3347511713")
.build()
MobileAds.initialize(
context,
config,
OnAdapterInitializationCompleteListener { status: InitializationStatus ->
if (status.isSuccessful) {
println("GMA SDK initialized successfully")
} else {
println("GMA SDK init failed: ${status.error}")
}
}
)
}
The OnAdapterInitializationCompleteListener receives an InitializationStatus object containing success state and any error details. Execute this on a background thread to avoid blocking the main thread during server communication.
iOS Initialization (Swift)
import GoogleMobileAds
func initializeGMA() {
MobileAds.shared.start { status in
if status == .completed {
print("GMA SDK initialized.")
} else {
print("GMA SDK init failed.")
}
}
}
The closure-based completion handler provides a streamlined pattern compared to the delegate-based Android approach.
Unity Initialization (C#)
using GoogleMobileAds.Api;
public class GmaInitializer : MonoBehaviour {
void Start() {
MobileAds.Initialize(initStatus => {
Debug.Log("GMA SDK initialized for Unity.");
});
}
}
Run this in a MonoBehaviour.Start() method to ensure initialization occurs at app launch.
Step 4: Verify Your Integration
Confirm correct setup with platform-specific build verification:
| Platform | Verification Command | Success Criteria |
|---|---|---|
| Android | ./gradlew assembleRelease or gradle build -x test |
Clean build with no compile errors |
| iOS | xcodebuild -scheme YourApp -configuration Release |
Successful archive or simulator build |
| Unity | File > Build Settings → Build and Run |
Test ad unit displays correctly |
Key Source Files in google/skills
Reference these authoritative files for platform-specific details:
-
skills/ads/google-mobile-ads-get-started/SKILL.md— Master skill definition outlining the complete workflow -
skills/ads/google-mobile-ads-get-started/references/android-get-started.md— Android dependency configuration andMobileAds.initialize()signature -
skills/ads/google-mobile-ads-get-started/references/ios-get-started.md— Swift package setup andMobileAds.shared.start()usage -
skills/ads/google-mobile-ads-get-started/references/unity-get-started.md— Unity package installation and C# initialization -
skills/ads/google-mobile-ads-get-started/assets/skadnetwork-identifiers.xml— Required iOS SKAdNetwork identifiers
Loading Ads After Initialization
Once InitializationStatus reports success, you can request banner, interstitial, rewarded, or native ads. Each format uses a dedicated view class:
AdView— Banner advertisementsInterstitialAd— Full-screen interstitialsRewardedAd— User-incentivized video ads
All require a placement ID from your AdMob console.
Summary
- Dependency: Add
ads-mobile-sdk(Android), Swift package (iOS), or Unity package via the GitHub URL - Configuration: Set your AdMob App ID in
InitializationConfig(Android),Info.plist(iOS), or Unity inspector - Initialization: Call
MobileAds.initialize()exactly once, using platform-specific listeners to handle completion - Verification: Build your project and run a test ad unit to confirm integration
- Source authority: All patterns derive from
google/skillsatskills/ads/google-mobile-ads-get-started/
Frequently Asked Questions
Do I need different App IDs for Android and iOS?
Yes. AdMob assigns platform-specific App IDs to each app entry. The sample IDs in google/skills (ca-app-pub-3940256099942544~3347511713 for Android, ~1458002511 for iOS) are Google's official test IDs. Replace these with your production IDs from the AdMob console before release.
Can I initialize Google Mobile Ads SDK on the main thread?
On Android, no. The MobileAds.initialize(context, config, listener) method performs network operations and must execute on a background thread. iOS and Unity handle threading internally, so the closure-based and C# callbacks run on appropriate queues automatically.
What are SKAdNetwork identifiers and why does iOS require them?
SKAdNetwork identifiers enable Apple's privacy-preserving ad attribution framework. The file assets/skadnetwork-identifiers.xml in google/skills contains the complete list of partner network IDs that Google Mobile Ads supports. Apple requires these in your Info.plist for App Store submission; omission causes ad serving failures on iOS 14+ devices.
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 →