Get Started

This guide is intended for publishers who want to monetize an Android app with AdMob and aren't using Firebase. If you plan to include Firebase in your app (or you're considering it), see the AdMob with Firebase version of this guide instead.

Integrating the Google Mobile Ads SDK into an app is the first step toward displaying ads and earning revenue. Once that's done, you can choose an ad format (such as native or rewarded video) and get a detailed set of steps for implementing it.

Prerequisites

  • Use Android Studio 1.0 or higher
  • Target Android API level 14 or higher

Import the Mobile Ads SDK

Apps can import the Google Mobile Ads SDK with a Gradle dependency that points to Google's Maven repository. In order to use that repository, you need to reference it in the app's project-level build.gradle file. Open yours and look for an allprojects section:

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        jcenter()
        maven {
            url "https://maven.google.com"
        }
    }
}

Add the maven directive above if it's not already present.

Next, open the app-level build.gradle file for your app, and look for a "dependencies" section.

Example app-level build.gradle (excerpt)

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.0.1'
    compile 'com.google.android.gms:play-services-ads:11.6.0'
}

Add the line in bold above, which instructs Gradle to pull in the latest version of the Mobile Ads SDK. Once that's done, save the file and perform a Gradle sync.

Initialize MobileAds

Before loading ads, have your app initialize the Mobile Ads SDK by calling MobileAds.initialize() with your AdMob App ID. This only needs to be done once, ideally at app launch. You can find your app's App ID in the AdMob UI.

Here's an example of how to call the initialize() method in an Activity:

Example MainActivity (excerpt)

Java

package ...
import ...
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    ...
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
        MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
    }
    ...
}

Kotlin

package ...
import ...
import com.google.android.gms.ads.MobileAds;

class MainActivity : AppCompatActivity() {
    ...
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
        MobileAds.initialize(this, "YOUR_ADMOB_APP_ID")
    }
    ...
}

Select an ad format

The 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 ads are rectangular image or text ads that occupy a spot within an app's layout. They stay on screen while users are interacting with the app, and can refresh automatically after a certain period of time. If you're new to mobile advertising, they're a great place to start.

Implement a banner

Interstitial

Interstitials are full-screen ads that cover the interface of an app until closed by the user. They're best used at natural pauses in the flow of an app's execution, such as in between levels of a game or just after completing a task.

Implement an interstitial

Native

Native is a component-based ad format that gives you the freedom to customize the way assets like headlines and calls to action are presented in their apps. By choosing fonts, colors, and other details for yourself, you can create natural, unobtrusive ad presentations that can add to a rich user experience.

AdMob offers two different ways to implement native ads: Native Ads Express and Native Ads Advanced. Native Ads Express has been designed to make getting on board with native ads as easy as possible, and it's a great choice if you're new to the format. Native Ads Advanced has been designed to maximize the amount of freedom you have in creating your presentations.

It's currently in a closed beta with a limited group of publishers.

Implement Native Ads Express Implement Native Ads Advanced

Rewarded Video

Rewarded video ads are full screen video ads that users have the option of watching in full in exchange for in-app rewards.

Implement Rewarded Video

发送以下问题的反馈:

此网页
AdMob for Android
AdMob for Android
需要帮助?请访问我们的支持页面