Get Started

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 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
  • For Kotlin apps, use the minimum Kotlin version 1.9.

Configure your app

  1. In your Gradle settings file, include the Google's Maven repository and Maven central repository:

    Kotlin

    pluginManagement {
      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'
  2. Add the dependencies for the Google Mobile Ads SDK to your app-level build file:

    Kotlin

    dependencies {
      implementation("com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.18.0-beta01")
    }

    Groovy

    dependencies {
      implementation 'com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:0.18.0-beta01'
    }
  3. Click Sync Now. For details on syncing, see Sync projects with Gradle files.

Initialize the Google Mobile Ads SDK

Call MobileAds.initialize() to initialize the Google Mobile Ads SDK. This must be called on a background thread, failure to do so may cause an "Application Not Responding" (ANR) error.

Kotlin

import com.google.android.libraries.ads.mobile.sdk.MobileAds
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig
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,
        // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713
        InitializationConfig.Builder("SAMPLE_APP_ID").build()
      ) {
        // Adapter initialization is complete.
      }
      // Other methods on MobileAds can now be called.
    }
  }
}

Java

import com.google.android.libraries.ads.mobile.sdk.MobileAds;
import com.google.android.libraries.ads.mobile.sdk.initialization.InitializationConfig;

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,
                  // Sample Ad Manager app ID: ca-app-pub-3940256099942544~3347511713
                  new InitializationConfig.Builder("SAMPLE_APP_ID")
                      .build(),
                  initializationStatus -> {
                    // Adapter initialization is complete.
                  });
              // Other methods on MobileAds can now be called.
            })
        .start();
  }
}

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.

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 RequestConfiguration.TagForChildDirectedTreatment or RequestConfiguration.TagForUnderAgeOfConsent, or otherwise take action before loading ads, ensure you do so before initializing the Google Mobile Ads SDK.

Select an ad format

The Google Mobile Ads SDK 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 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

Interstitial

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

Rewarded

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

Rewarded interstitial

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

App open

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