Stay organized with collections Save and categorize content based on your preferences.
Integrating the Google Mobile Ads SDK into an app is the first step toward displaying ads and earning revenue. Once you've integrated the SDK, you can choose an ad format (such as native or rewarded video) and follow the steps to implement it.
Before you beginTo prepare your app, complete the steps in the following sections.
App prerequisitesMake sure that your app's build file uses the following values:
23
or higher34
or higherRegister your app as an AdMob app by completing the following steps:
Sign in to or sign up for an AdMob account.
Register your app with AdMob. This step creates an AdMob app with a unique AdMob App ID that is needed later in this guide.
In your Gradle settings file, include the Google's Maven repository and Maven central repository:
KotlinpluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "My Application" include(":app")Groovy
pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } rootProject.name = "My Application" include ':app'
Add the dependencies for the Google Mobile Ads SDK to your app-level build file:
Kotlindependencies { implementation("com.google.android.gms:play-services-ads:24.2.0") }Groovy
dependencies { implementation 'com.google.android.gms:play-services-ads:24.2.0' }
Click Sync Now. For details on syncing, see Sync projects with Gradle files.
Add your AdMob app ID, as identified in the AdMob web interface, to your app's AndroidManifest.xml
file. To do so, add a <meta-data>
tag with android:name="com.google.android.gms.ads.APPLICATION_ID"
. You can find your app ID in the AdMob web interface. For android:value
, insert your own AdMob app ID, surrounded by quotation marks.
<manifest>
<application>
<!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>
In a real app, replace the sample app ID with your actual AdMob app ID. You can use the sample ID if you're just experimenting with the SDK in a Hello World app.
Also, note that failure to add the <meta-data>
tag exactly as shown results in a crash with the message:
Missing application ID.
(Optional) Declare AD_ID
permission for previous versions to work with Android 13.
If your app uses the Google Mobile Ads SDK version 20.4.0 or higher, you can skip this step since the SDK automatically declares the com.google.android.gms.permission.AD_ID
permission and is able to access the Advertising ID whenever it's available.
For apps that use the Google Mobile Ads SDK version 20.3.0 or lower and are targeting Android 13, you must add the com.google.android.gms.permission.AD_ID
permission in the AndroidManifest.xml
file for the Google Mobile Ads SDK to access the Advertising ID:
<manifest> <application> <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/> <!-- For apps targeting Android 13 or higher & GMA SDK version 20.3.0 or lower --> <uses-permission android:name="com.google.android.gms.permission.AD_ID"/> </application> </manifest>
To learn more about the com.google.android.gms.permission.AD_ID
permission declaration, including how to disable it, refer to this Play Console article.
Before loading ads, initialize the Google Mobile Ads SDK by calling
MobileAds.initialize()
.
This method initializes the SDK and calls a completion listener once both the Google Mobile Ads SDK and adapter initializations have completed, or after a 30-second timeout. This needs to be done only once, ideally at app launch.
Note: If you're using AdMob Mediation, wait until the completion handler is called before loading ads. This ensures that all mediation adapters are initialized.Ads may be preloaded by the Google Mobile Ads SDK or mediation partner SDKs upon initialization. If you need to obtain consent from users in the European Economic Area (EEA), set any request-specific flags, such as setTagForChildDirectedTreatment()
or setTagForUnderAgeOfConsent()
, or otherwise take action before loading ads, ensure you do so before initializing the Google Mobile Ads SDK.
Here's an example of how to call the initialize()
method on a background thread within an Activity:
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
public class MainActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new Thread(
() -> {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(this, initializationStatus -> {});
})
.start();
}
}
Kotlin
import com.google.android.gms.ads.MobileAds
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val backgroundScope = CoroutineScope(Dispatchers.IO)
backgroundScope.launch {
// Initialize the Google Mobile Ads SDK on a background thread.
MobileAds.initialize(this@MainActivity) {}
}
}
}
Select an ad format
The Google Mobile Ads SDK is now imported and you're ready to implement an ad. AdMob offers a number of different ad formats, so you can choose the one that best fits your app's user experience.
Banner ad units display rectangular ads that occupy a portion of an app's layout. They can refresh automatically after a set period of time. This means users view a new ad at regular intervals, even if they stay on the same screen in your app. They're also the simplest ad format to implement.
InterstitialInterstitial ad units show full-page ads in your app. Place them at natural breaks and transitions in your app's interface, such as after level completion in a gaming app.
NativeNative ads are ads where you can customize the way assets such as headlines and calls to action are presented in your apps. By styling the ad yourself, you can create a natural, unobtrusive ad presentations that can add to a rich user experience.
RewardedRewarded ad units enable users to play games, take surveys, or watch videos to earn in-app rewards, such as coins, extra lives, or points. You can set different rewards for different ad units, and specify the reward values and items the user received.
Rewarded interstitialRewarded interstitial is a new type of incentivized ad format that lets you offer rewards, such as coins or extra lives, for ads that appear automatically during natural app transitions.
Unlike rewarded ads, users aren't required to opt in to view a rewarded interstitial.
Instead of the opt-in prompt in rewarded ads, rewarded interstitials require an intro screen that announces the reward and gives users a chance to opt out if they want to do so.
Implement rewarded interstitial ads
App openApp open is an ad format that appears when users open or switch back to your app. The ad overlays the loading screen.
Additional resourcesThe Google Mobile Ads repository on GitHub demonstrates how to use the different ad formats that this API offers.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-05-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-05-10 UTC."],[[["Integrating the Google Mobile Ads SDK is the initial step to display ads in your app and generate revenue, followed by choosing an ad format (like native or rewarded video) and implementing it."],["Before starting, ensure your app has a minimum SDK version of 21, a compile SDK version of 33 or higher, and is registered with AdMob to obtain a unique AdMob App ID."],["Configure your app by including Google's and Maven Central's repositories, adding the Google Mobile Ads SDK dependency, and inserting your AdMob App ID in your `AndroidManifest.xml` file."],["Initialize the Google Mobile Ads SDK before loading ads by calling `MobileAds.initialize()` once, preferably during app launch, to ensure all mediation adapters are initialized."],["Choose from various ad formats offered by AdMob, including banner, interstitial, native, rewarded, rewarded interstitial, and app open ads, to best suit your app's user experience."]]],["To start displaying ads, integrate the Google Mobile Ads SDK into your app. Ensure your app's minimum SDK version is 21 or higher, and compile SDK is 34 or higher. Register your app in AdMob to get a unique App ID. Configure your app by including Google's Maven and Maven central repositories, adding SDK dependencies in the build file, and inserting your AdMob app ID into `AndroidManifest.xml`. Initialize the SDK with `MobileAds.initialize()` on app launch, preferably on a background thread. Choose an ad format (banner, interstitial, native, rewarded, rewarded interstitial, or app open) to implement.\n"]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3