How to insert AdMob Banner Ad in your Android App

How to insert AdMob Banner Ad in your Android App

Banner Ad is one of the Ad types of AdMob which helps you in generating revenue by displaying Ads on your App. This guide shows you how to integrate banner ads from AdMob into an Android app.

I use sample app id and banner id for the test. Because if we use read ids for test AdMob will ban our account. So always use sample ad codes for test. After all codes and app modified/developed you can place AdMob real ids.

Integrate AdMob Banner ads in Android App

To do that please follow the instructions.

How to insert AdMob Banner Ad in your Android App

in build.gradle(:app) add following code.

implementation ''

Now click on Sync now.

in AndroidManifest.xml add this meta tag.


Now open your activity_main.xml layout. Then add following code.

app:layout_constraintVertical_bias="1.0" />

We use ad size for SMART_BANNER because it fit to the screen and better experience.

in add following code inside oncreate method.

MobileAds.initialize(this, initializationStatus -> {

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

Now run your application. if you get error like this “Cannot fit requested classes in a single dex file” add following code in build.gradle(:app).

multiDexEnabled true

Then add this code in dependencies.

implementation ''
Here is the full code – build.gradle(:app)
plugins {
id ''
id ''

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"

defaultConfig {
applicationId "com.techedutricks.techedutricks"
minSdkVersion 17
targetSdkVersion 30
versionCode 1
versionName "1.0"
multiDexEnabled true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), ''
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8

dependencies {

implementation 'androidx.appcompat:appcompat:1.3.0'
implementation ''
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation ''
implementation ''
implementation ''
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation platform('')
implementation ''
apply plugin: ''

Now all done. If you have any problem click here to get support from TechEdutricks Community. And also share your ideas with us!!

Danushka Sanjeewa

Danushka Sanjeewa is a Software engineer with more than 5 years of experience in Android App Development, Web Development, Marketing, Graphic design, Video editing, and WordPress. And also Writer/Founder of

Leave a Comment