How to Use Google AdMob in Android App
Thinking about monetizing your Android app? Google AdMob is one of the most popular and straightforward ways to start earning revenue from your creations. This guide will walk you through the entire process, from setting up your account to implementing the most common ad formats, complete with code examples so you can follow along.
What is Google AdMob?
Google AdMob is a mobile advertising platform created by Google that allows developers to serve ads inside their mobile apps. It acts as a middleman, connecting advertisers who want to reach a mobile audience with app developers who have that audience. By integrating the AdMob SDK (Software Development Kit) into your app, you can display ads for products, services, or other apps and get paid for impressions (how many times ads are seen) or clicks.
It’s a powerful way to generate a sustainable income stream from your app, whether it's a free game, a utility tool, or a social platform. AdMob supports several ad formats, giving you the flexibility to choose what works best for your app’s user experience.
Step 1: Set Up Your AdMob Account
Before you can write a single line of code, you need an AdMob account and a place to register your app. If you already have a Google account, this process is quick.
Sign Up for AdMob: Go to the AdMob website and sign up using your Google account. You'll be asked to provide some basic information, like your country, time zone, and billing currency.
Add Your App: Once your account is set up, you’ll see a dashboard. Click on "Apps" > "Add app" to register the application you want to monetize.
Select the platform (Android).
You’ll be asked if your app is listed on a supported app store. If it's already on the Google Play Store, you can search for and select it. If not, you can add it manually by providing an app name.
Create Ad Units: An ad unit is a specific space in your app where ads are displayed. You need to create at least one ad unit for any ad format you want to use.
In your app’s dashboard in AdMob, click "Ad units" > "Add ad unit."
Choose an ad format (Banner, Interstitial, Rewarded, etc.).
Give your ad unit a descriptive name, like "Main Banner Bottom" or "Level Complete Interstitial." This helps you keep track of performance later.
After creating your app and ad units, AdMob will provide you with two crucial pieces of information:
Your App ID: A unique identifier for your app within AdMob.
Your Ad Unit ID(s): Unique identifiers for each ad unit you create.
Keep these handy, you'll need them in your Android project.
Important Note: During development and testing, you should always use Google’s sample App IDs and Ad Unit IDs. Using your live ad units for testing can get your account flagged or suspended for invalid activity. We'll use the test IDs in the examples below.
Step 2: Integrate the Google Mobile Ads SDK in Android Studio
With your AdMob account ready, it's time to add the necessary tools to your Android app project. This involves adding a dependency and configuring your app manifest.
Add the Gradle Dependency
First, open your app-level build.gradle.kts (or build.gradle if you're using Groovy) file and add the Google Mobile Ads SDK as a dependency:
Sync your project with the Gradle files after adding this line.
Update Your AndroidManifest.xml
Next, you need to add your AdMob App ID to the AndroidManifest.xml file. This authenticates your app with AdMob. Open app/src/main/AndroidManifest.xml and add the following <meta-data> tag inside the <application> element. Replace the sample ID with your own actual App ID when you're ready to publish.
Initialize the SDK
Before you can load any ads, the SDK must be initialized. This only needs to happen once, ideally when your app first launches. A great place to do this is in the onCreate() method of your Application class or your main Activity.
In your main Activity's onCreate() method, add this call:
That's it for the basic setup! Your app is now ready to request and display ads.
Step 3: Implement Different Ad Formats
Now for the fun part: adding ads to your app’s UI. Let's look at how to implement the three most common ad formats: Banner, Interstitial, and Rewarded.
1. How to Add a Banner Ad
Banner ads are the most basic format. They are rectangular image or text ads that sit either at the top or bottom of the screen, staying on-screen while users interact with the app.
Add AdView to Your XML Layout:
Open the layout file where you want the banner to appear (e.g., activity_main.xml) and add an AdView element. Use a test Ad Unit ID for now.
The ads:adSize attribute defines the size of the banner. BANNER is a standard 320x50 size. For better results on different screen sizes, consider using ADAPTIVE_BANNER.
Load the Ad in Your Activity:
In your Activity file's onCreate() method, find the AdView and load an ad. It looks like this in Kotlin:
2. Adding Interstitials
Interstitial ads fill most of the screen and are generally displayed during natural transitions in your app, such as between game levels or after completing a task. Loading them is also an asynchronous process.
Load an Interstitial Ad:
Show the Interstitial Ad:
3. Implementing a Rewarded Ad
Rewarded ads, also known as rewarded video ads, offer users an in-app reward (like extra coins, lives, or features) in exchange for watching a video ad. They are fantastic for engagement, especially in games.
Load a Rewarded Ad:
Show the Rewarded Ad:
The important difference in this code is the OnUserEarnedRewardListener callback. Inside the callback, implement the code that grants the reward to the user.
Best App Monetization Practices
There are simple yet important tips to follow to ensure a good user experience and prevent your app from becoming "spammy":
Do not click your own ads: You should never click on your own ads to test them.
Respect user time: If an ad has a large number of each ad, you should create a timeout between them, like one or two minutes.
Finally, your first steps can seem complicated, but you will find this guide, along with Android and iOS documentation, helpful as you learn.
Final Thoughts
Integrating AdMob into your Android app is a proven method for monetization. By adding the SDK, implementing formats like banner and interstitial ads carefully, and following best practices for user experience, you create a new and valuable revenue stream. Remember to always use test ads during development and to place live ads in ways that feel natural and unobtrusive.
Once your ads are live, the next step is tracking their performance. Keeping tabs on revenue, impressions, and fill rates across a half-dozen different platforms can easily turn into a mess of dashboards and spreadsheets. We built Graphed because we believe analyzing that data shouldn't be so difficult. By connecting your AdMob, Google Analytics, and other data sources, you can ask questions in plain English like "Show me my AdMob revenue versus DAU (daily active users) for the last 30 days" and get instant, real-time dashboards that show you what's working - automating your entire reporting process so you can get back to building your app.