【Kotlin/Android Studio】How to install AdMob! Implementing banner ads
What you will learn from this article
- How to implement ads in an app developed using Android Studio/Kotlin
- How to set up and use AdMob
- The process of placing ads with AdMob
- How to create the logic for Banner ads
- Implementing test ads in a developing app
index
[open]
\ アプリをリリースしました /
Environment
- Android Studio:Meerkat
- Kotlin:2.0.21
What is Google AdMob?
AdMob is a service provided by Google that allows you to place advertisements on mobile apps such as iOS and Android.
By providing AdMob with a space on the app screen to place ads, they will automatically deliver ads based on the user's information.
The basic service content and usage are the same as Google AdSense, which allows you to add advertisements to web pages.
Ad Units
AdMob allows you to choose from four types of ad units.
Banner
Banner-type advertisements placed at the top or bottom of the app screen. They are always displayed and the content is updated at regular intervals.
Recommended article: 【Kotlin/Android Studio】How to install AdMob! Implementing banner ads
Interstitial
Advertisements that are displayed full-screen during screen transitions and flows. They will not disappear unless you press the close button.
Recommended article: 【Swift UI】How to implement AdMob interstitial ads! Display when screen transition occurs
Native
Customizable ads that can be integrated into the app design.
Reward
Ads that ask users to watch videos for several tens of seconds. You can implement a process to have users watch ads in exchange for rewards such as points or stamina.
Recommended article: 【Swift UI】How to implement AdMob reward ads! GADFullScreenContentDelegate
How to Implement Banner Ads in an Android App
This guide summarizes how to integrate ads into an Android app using Google AdMob.
Steps
- Register a Google AdMob account
- Add your app to AdMob
- Add the Mobile Ads SDK in build.gradle (Module)
- Add your App ID in the manifest file
- Implement AdView (banner view)
- Initialize the SDK and load the ad
How to Register a Google AdMob Account
You must first register for a Google AdMob account to get started.
You can easily register using the link above. The registration steps vary depending on whether you already have a Google AdSense account, so follow the appropriate instructions based on your situation.
If you already have a Google AdSense account, confirm your registration details and click "Create AdMob Account" if everything looks correct.
After following the instructions, you'll be taken to the AdMob home screen.
If you don’t have a Google AdSense account, go to the home screen's sidebar and register your payment information via “Payments”.
Add Your App to AdMob
From the home screen sidebar, go to “Apps” > “Add App”, choose your platform, and check the appropriate boxes. You can register your app even if it hasn’t been published on the Play Store. Select No for "Is your app listed on a supported app store?" and proceed by clicking “Next”.
On the next screen, enter your app’s name and click “Add App” to complete registration.
This completes the app registration. After implementing the ad code described below and publishing your app to the store, you can input store information and start the review process. (The screenshots are from iOS, but the steps are the same for Android.)
Next, choose the type of ad unit you want to create.
Select your preferred ad unit type, enter a name, and create the unit.
This will display your App ID and Ad Unit ID. You'll need these IDs later, but you can always check them again, so it’s okay to close the dialog.
Add the Mobile Ads SDK via build.gradle (Module)
Add the Mobile Ads SDK to your project. In your build.gradle (Module) file, add the line below and click “Sync Now”.
dependencies {
// ------------------------------
implementation("com.google.android.gms:play-services-ads:24.2.0")
}
Add App ID to the Manifest File
Add your AdMob App ID to the manifest file. Open AndroidManifest.kt and add the following meta-data tag inside the application tag. If this is missing, ads won’t display properly.
<?xml version="1.0" encoding="utf-8"?>
<manifest>
// ------------------------------
<application>
// ------------------------------
// Add the following
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713"/>
<activity>
// ------------------------------
</activity>
</application>
</manifest>
The android:value attribute should be your actual App ID from AdMob. For testing purposes, you can use ca-app-pub-3940256099942544~3347511713.
Implement AdView (Banner View)
In your layout file, implement the AdView. Use adSize="BANNER" and pass the banner ad unit ID to adUnitId. For testing, use ca-app-pub-3940256099942544/6300978111.
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
Initialize SDK and Load the Ad
Once the layout is done, initialize the SDK and load the ad in your activity.
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// Initialize
MobileAds.initialize(this)
// Load Ad
var adView: AdView = findViewById(R.id.adView)
adView.loadAd(AdRequest.Builder().build())
}
This completes the implementation of AdMob ads. Run your app and check if the ad is displayed like below.
Recommended article: How to dynamically add banner ads in Kotlin/Android/AdMob
I am still learning, so if you find any mistakes or shortcomings, I would appreciate it if you could let me know.
Thank you for reading.






