<br />

Integrating Google Mobile Ads SDK (Legacy) 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 begin

To prepare your app, complete the steps in the following sections.

### App prerequisites

- Make sure that your app's build file uses the following values:

  - Minimum SDK version of `24` or higher
  - Compile SDK version of `35` or higher

## Configure your app

1. In your Gradle settings file, include the
   [Google's Maven repository](https://maven.google.com/web/index.html) and
   [Maven central repository](https://search.maven.org/artifact):

   ### Kotlin

   ```kotlin
   pluginManagement {
     repositories {
       google()
       mavenCentral()
       gradlePluginPortal()
     }
   }

   dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
     repositories {
       google()
       mavenCentral()
     }
   }

   rootProject.name = "My Application"
   include(":app")
   ```

   ### Groovy

   ```groovy
   pluginManagement {
     repositories {
       google()
       mavenCentral()
       gradlePluginPortal()
     }
   }

   dependencyResolutionManagement {
     repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
     repositories {
       google()
       mavenCentral()
     }
   }

   rootProject.name = "My Application"
   include ':app'
   ```
2. Add the dependencies for Google Mobile Ads SDK (Legacy) to your app-level build file:

   ### Kotlin

   ```kotlin
   dependencies {
     implementation("com.google.android.gms:play-services-ads:25.5.0")
   }
   ```

   ### Groovy

   ```groovy
   dependencies {
     implementation 'com.google.android.gms:play-services-ads:25.5.0'
   }
   ```
3. Click **Sync Now** . For details on syncing, see
   [Sync projects with Gradle files](https://developers.android.com/build#sync-files).

4. Add your Ad Manager app ID, as
   [identified in the Ad Manager web interface](https://support.google.com/admanager/answer/15014197),
   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 Ad Manager web interface. For
   `android:value`, insert your own Ad Manager app ID,
   surrounded by quotation marks.

   ```xml
   <manifest>
     <application>
       \<!-- Sample Ad Manager app ID: ca-app-pub-3940256099942544\~3347511713 --\>
   \<meta-data
   android:name="com.google.android.gms.ads.APPLICATION_ID"
   android:value="SAMPLE_APP_ID"/\>
     </application>
   </manifest>
   ```

   Replace <var class="readonly" translate="no">SAMPLE_APP_ID</var> with your Ad Manager app ID. While
   testing, use the sample app ID shown in the previous example.

   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 Google Mobile Ads SDK (Legacy) 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 Google Mobile Ads SDK (Legacy) 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 Google Mobile Ads SDK (Legacy) to access the
   Advertising ID:

   ```xml
   <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](https://support.google.com/googleplay/android-developer/answer/6048248).

## Initialize the Google Mobile Ads SDK (Legacy)

Before loading ads, initialize Google Mobile Ads SDK (Legacy) by calling [`MobileAds.initialize()`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/MobileAds.md.txt#initialize(android.content.Context,%20com.google.android.gms.ads.initialization.OnInitializationCompleteListener)).

This method initializes the SDK and calls a completion listener once both
Google Mobile Ads SDK (Legacy) and adapter initializations have completed, or after a
30-second timeout. This needs to be done only once, ideally at app launch.

If you're using mediation, wait until the
completion handler is called before loading ads. This ensures that all
mediation adapters are initialized.

**Ads may be preloaded by Google Mobile Ads SDK (Legacy) or mediation partner SDKs
upon initialization.** If you need to obtain consent from users in the European
Economic Area (EEA), the United Kingdom (UK), or Switzerland, set any
request-specific flags, such as

[`setTagForChildDirectedTreatment()`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/RequestConfiguration.Builder.md.txt#setTagForChildDirectedTreatment(int))
or
[`setTagForUnderAgeOfConsent()`](https://developers.google.com/ad-manager/mobile-ads-sdk/android/reference/com/google/android/gms/ads/RequestConfiguration.Builder.md.txt#setTagForUnderAgeOfConsent(int)),

or
otherwise take action before loading ads, ensure you do so before initializing
Google Mobile Ads SDK (Legacy).

Here's an example of how to call the `initialize()` method on a background
thread within an Activity:

### Java

```java
new Thread(
        () -> {
          // Initialize the Google Mobile Ads SDK on a background thread.
          MobileAds.initialize(this, initializationStatus -> {});
        })
    .start();
```

### Kotlin

```kotlin
CoroutineScope(Dispatchers.IO).launch {
  // Initialize the Google Mobile Ads SDK on a background thread.
  MobileAds.initialize(this@MyActivity) {}
}
```

## Select an ad format

Google Mobile Ads SDK (Legacy) is now imported and you're ready to implement an ad.
Ad Manager offers a number of different ad formats, so
you can choose the one that best fits your app's user experience.

### Banner

![](https://developers.google.com/static/admob/images/format-banner.svg)

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.

[Implement banner ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/banner.md.txt)

### Interstitial

![](https://developers.google.com/static/admob/images/format-interstitial.svg)

Interstitial 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.

[Implement interstitial ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/interstitial.md.txt)

### Native

![](https://developers.google.com/static/admob/images/format-native.svg)

Native 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.

Google Ad Manager offers two ways to implement native ads: native styles and
standard native ads through custom rendering.

Native styles has been designed to simplify the implementation of native ads,
and it's a great choice if you are new to the format. Custom rendering has been
designed to maximize the freedom you have in creating your presentations.

[Implement native styles](https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/styles.md.txt)
[Implement native ads (custom rendering)](https://developers.google.com/ad-manager/mobile-ads-sdk/android/native.md.txt)

### Rewarded

![](https://developers.google.com/static/admob/images/format-rewarded.svg)

Rewarded 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.

[Implement rewarded ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/rewarded.md.txt)

### Rewarded interstitial

![](https://developers.google.com/static/admob/images/format-rewarded-interstitial.svg)

Rewarded 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](https://developers.google.com/ad-manager/mobile-ads-sdk/android/rewarded-interstitial.md.txt)

### App open

![](https://developers.google.com/static/admob/images/format-app-open.svg)

App open is an ad format that appears when users open or switch back to your
app. The ad overlays the loading screen.

[Implement app open ads](https://developers.google.com/ad-manager/mobile-ads-sdk/android/app-open.md.txt)

## Additional resources

The [Google Mobile Ads repository](https://github.com/googleads/googleads-mobile-android-examples) on GitHub demonstrates
how to use the different ad formats that this API offers.