Admob banner is not showing up

Alex picture Alex · Feb 1, 2017 · Viewed 13.6k times · Source

My admob banner is not showing up, I have gone through the guide found here https://firebase.google.com/docs/admob/android/quick-start

MainActivity

private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-3940256099942544/6300978111");
    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
}

Layout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.myapplication.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>
</RelativeLayout>

In my Manifest, I have this permission

<uses-permission android:name="android.permission.INTERNET" />

Project Gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

app gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.example.myapplication"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.google.firebase:firebase-ads:10.0.1'
    compile 'com.google.firebase:firebase-core:10.0.1'
    testCompile 'junit:junit:4.12'
}



apply plugin: 'com.google.gms.google-services'

Log

01-31 20:44:49.586 3556-3556/? D/ucsBai_ConnectionManager: mPackageReceiver Action android.intent.action.PACKAGE_ADDED
01-31 20:44:58.836 19607-19607/com.example.myapplication I/FA: App measurement is starting up, version: 10084
01-31 20:44:58.836 19607-19607/com.example.myapplication I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
01-31 20:44:58.836 19607-19607/com.example.myapplication D/FA: Debug-level message logging enabled
01-31 20:44:58.836 19607-19607/com.example.myapplication D/FA: AppMeasurement singleton hash: 23949389
01-31 20:44:58.846 19607-19607/com.example.myapplication V/FA: Collection enabled
01-31 20:44:58.846 19607-19607/com.example.myapplication V/FA: App package, google app id: com.example.myapplication, 1:665936977222:android:13c3c6a65bcbec53
01-31 20:44:58.846 19607-19607/com.example.myapplication I/FA: To enable faster debug mode event logging run:
                                                                 adb shell setprop debug.firebase.analytics.app com.example.myapplication
01-31 20:44:58.906 19607-19607/com.example.myapplication V/FA: Registered activity lifecycle callback
01-31 20:44:58.916 19607-20434/com.example.myapplication V/FA: Using measurement service
01-31 20:44:58.916 19607-20434/com.example.myapplication V/FA: Connecting to remote service
01-31 20:44:59.816 19607-20434/com.example.myapplication V/FA: Connection attempt already in progress
01-31 20:45:00.116 19607-20434/com.example.myapplication D/FA: Connected to remote service
01-31 20:45:00.116 19607-20434/com.example.myapplication V/FA: Processing queued up service tasks: 2
01-31 20:45:05.156 19607-20434/com.example.myapplication V/FA: Inactivity, disconnecting from the service

Answer

Pranav Darji picture Pranav Darji · Feb 1, 2017

First Open the https://apps.admob.com/ and then select your application from there now select the Monetize Tab from there now expand the view setup instruction

enter image description here

Here you have to put your App ID

MobileAds.initialize(getApplicationContext(), "ca-app-pub-1440645979698474~6985293144"); // replace with yours

And for xml enter image description here

Select from adunits

<com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-1440645979698474/3892225947"> 

Replace with your adUnitId and you are done.