How to Add Admob ADS in your Android App

How to put admob ads in Android

Admob is a mobile advertisements platform run by google. admob is better than any other ad networks because the payment and quality is good. they are the most trusted ad network and millions of advertisers use admob.

We will learn how to add/integrate Google Admob ads into your android app and make money from your app users by showing ads to them In this tutorial.


Types of Admob Ads

  1. Banner Ads – (Basic Ads,This type of ads placed in the bottom of your app)
  2. Interstitial Ads – (Full screen ads)
  3. Native Ads – (You can customize this type of ads to match the look of your app)
  4. Rewarded Video – (your user can watch this video ads if you want to let them use your app or game free)

in this tutorial, we will try to add a banner ad into our app.

Steps to show ads in your app

  1. Sign Up for Google Admob Account
  2. Register your app and create an Adunit
  3. Add the SDK
  4. Add some codes in your app in android studio

Sign Up on Admob for an account, Sign Up for Admob here.

after sign up, Create a Banner ad format, get your app id and get your unique adunit id for your app. then let’s continue to next step

Add the SDK

In this step, we are going to add the ad sdk to your app. after adding the sdk and a few lines of code, your app will be able to show ads.

Open your android studio and in the navigation menu, select Tools > Firebase. a new menu will appear


In bottom of the menu, you can see “Admob” , select “add a banner ad to your app“.

Select “Connect to firebase“. now the android studio will try to connect to firebase, you will need log in to your gmail account, you might need logged in or sign up into firebase also. wait until the android studio successfully connect to firebase.


After connection, a new menu will appear asking you to add your app to firebase. enter your app name into the text box and select your country. click “Connect to firebase” button. and wait few minutes until android studio connect your app to firebase and do some work in the background.


Now the android studio will ask you to add the SDK to your project gradle files, this adds the ads sdk library to your app. this library is required to load and show ads in your app.

Next click on the Add admob to your app button, a new menu will appear asking your permission to add the dependencies .

Click “Accept changes” and you need to wait until android studio sync the library with gradle files and add the required dependencies.

Now your app is almost ready to show ads. in next steps, we will need to add some xml and java codes into our app.

Adding codes to layout and java

This is the final step, if all of the above steps have completed, let’s continue

Open your activity_main.xml layout file, or other layout where you want to add banner ad. in that layout, add the following code in the top.



Next, add this code, this code places ad banner view in the bottom of your app layout.

< android:id="@+id/adView"


Screenshot for reference


you can see red in “ads:adUnitId=”@string/banner_ad_unit_id“>”. the red indicates error. we need add the adunit id

in the Strings.xml.  you need your adUnit Id from admob. and go to res > values > strings.xml.


In the strings.xml, add this adunit id code.



Replace the “ca-app-pub-3940256099942544/6300978111” with your adunit id later. this current id is for testing ads. keep in mind that you should always use test adunit id. testing your app with your real adunit id is against admob policy and they can suspend your admob account. you should use your real adunit id only when releasing the app.


So we added sdk, added codes in the layout file, added adunit id in the strings. next we need add some codes to the java.

Open your or the activity where you wish to add the ads. add the codes to the java, this is full code, your java code should look like this.

package com.example.myapp.myapplication;

import android.os.Bundle;


public class MainActivity extends AppCompatActivity {

    private AdView mAdView;

    protected void onCreate(Bundle savedInstanceState) {

        mAdView = (AdView) findViewById(;
        AdRequest adRequest = new AdRequest.Builder().build();



Screenshot of the java code in android studio

This is it.

We have completed all the steps. now your app should be ready, we can test it now. remember to test it with test adunit id only



The app is now launched and a test ad is shown in the bottom of your screen. this is a test ad, by replacing the adunit id in strings.xml with your unique ad unit id, the real ads will be shown.

If you need more help, you can use the comments below

Related Posts

Add Admob ads in recyclerview in android

How to add admob native ads to recyclerview in android java Adding admob native ads into android recyclerview isn’t easy like other admob ads. You will need…

Download WebView Flutter Source Code for Android and iOS

Easily create android and iOS WebView app for your websites, the much-awaited flutter WebView source code is here. Are you looking for a flutter WebView source code…

Fix uses-sdk:minSdkVersion 16 cannot be smaller than version 19 declared in library [:_flutter_android]

This error can be fixed by modifying build.gradle file in the flutter In android studio: go to android>app>build.gradle and modify it as follows:

Get Your Own Android Mobile App for Your Website Today

Are you looking to expand your online presence and reach more customers? In today’s digital age, having a mobile app is an essential tool to connect with…

Why making an app for your website can help your business to grow

In today’s digital age, it’s more important than ever to have a strong online presence. Whether you’re running a business, a blog, or a personal website, having…

Fix android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference

Here is how to Fix Android Studio Error Attempt to invoke virtual method ‘boolean android.content.Intent.migrateExtraStreamToClipData(android.content.Context)’ on a null object reference This error is caused by a number…

Leave a Reply

Your email address will not be published. Required fields are marked *