Integrating New Google Admob with Banner and Interstitial ads

In this tutorial, you will learn how to integrate the new Google Admob with banner and interstitial ads into your Android application. The new AdMob is a streamlined user interface, to make it even easier for you to monetize and promote your apps in minutes. Maximize your earnings with the new AdMob improved tools to help app developers build thier business. We will create a simple view that launches an Interstitial on start and show a single banner advertisement. So lets begin…


Sign up as an Admob Publisher here. Log in to your dashboard once you have your account approved.

Identify your publisher ID on the top right of your dashboard.


Open the Monetize tab and create an ad unit for your application. You should be able to see your ad unit after selecting an app on your left panel.


Download the new Google Play Services Library using the Android SDK Manager in your Eclipse IDE.


Import Google Play Services Library into your Eclipse IDE. I’ve found mine in D:\Eclipse\sdk\extras\google\google_play_services\libproject . You will have to search the folder yourself.


Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project NewAdmobTutorial.

Application Name : NewAdmobTutorial

Project Name : NewAdmobTutorial

Package Name : com.androidbegin.newadmobtutorial

Import Google Play Services Library into your App.


Open your and paste the following code.

In this, a test device is being used to run test ads. Its highly recommended to test your ads using test ads to prevent invalid clicks that will cause suspension of your AdMob publisher account. To generate a Test Device ID, simply type in some random text into addTestDevice as shown below.

Run your app, and filter your logcat with the word “ads” as shown below. You should be able to generate some unique strings.


Now paste the Test Device ID into addTestDevice. You have to generate your own Test Device ID, because each Android Device has an unique ID.

Showing Real Ads

To show real ads, just remove the two lines by commenting it as shown below.

Next, create an XML graphical layout for your MainActivity. Go to res > layout > Right Click on layout > New > Android XML File

Name your new XML file activity_main.xml and paste the following code.


In your AndroidManifest.xml, we need to declare an activity for Google Play Services and permissions to allow the application to access to the Internet and check network status. Open your AndroidManifest.xml and paste the following code.




NewAdMobTutorial (4.7 MiB, 221 downloads)
  • mina kumari

    unfortunately app has stopped

    • AndroidBegin

      Hi, I’ve just tested it again on API 4.3 , its running fine. Did you generate your own Device Test ID to test it out first? Show me some logcat errors please. Thanks.

      • mina kumari

        thanks now work

        but only display in emulator when i publish app and install device not load ads only open blank page

        • AndroidBegin

          If it works in your emulator, it should work on your device too. Please double check your Test Device ID.

  • ibrahim

    Thx very much

  • J Ahsan

    Hi got an error.Please help …java.lang.NoClassDefFoundError:

    • AndroidBegin

      Hi, did you import the Google Play Services Library into your project?

      • J Ahsan

        I have added the as a android code—> marked it as a library–>went to my project properties to reference it–> cleaned both project –RUn (ERROR)

        • Deepak Kanyan

          plz check you import

        • TechnoRapper dotcom

          same problem with me

          • Mohamed Ahmed

            is the problem still existing ?

          • Mohamed Ahmed

            is the problem still exist ?

        • Mohamed Ahmed

          is the problem still exist ?

  • bluesky214

    You should have version for latest android studio,much easier to use when importing sdk,libraries and jar files

    • AndroidBegin

      Agreed with Bluesky.

  • Me

    Also getting java.lang.NoClassDefFoundError:…I have tried for hours to figure out why, but no answer.

  • Amit Kumar Khare

    Working Like a charm. Thanks a lot. :)

    • Sanjay

      Hi Amit,

      This is Sanjay. Can you please send me a sample hello world application integrated with new admob. Please.
      My mail id is

      • Amit Kumar Khare

        Hello, I sent you. please check your mail. and let me know if it worked for you. Take care.

      • Amit Kumar Khare

        sent you on your email. Please check and have fun.

  • Alex

    I do not understand why an error: “The constructor InterstitialAd(FileCategoryActivity) is undefined”?

  • sameer

    my app was removed by google play saying that Interstitial ads may only be displayed inside of the app they came with. So how to achieve this?

  • Sanjay

    Can any one help me in integrating admob with a sample Hello world. Please help me on adding new admob with the app.

    • Mohamed Ahmed

      have you solved the problem ?

  • william aristizabal

    properties android reference error google play service eclipse

  • Sinchan Maitri

    ” Exception raised during rendering: com/google/android/gms/ads/AdView : Unsupported major.minor version 51.0

    Exception details are logged in Window > Show View > Error Log ”

    i am getting this for all the apps. Please suggest me what to do….

  • TC Ibrahim YENER

    Excellent tutorial. Easy to understand and easy to follow.
    Thanks for it.
    Keep up good work.

  • Nelson Osorio

    Thank you!! Great Tutorialt!!

  • alex

    1 error to create apk
    Dex Loader] Unable to execute dex: Multiple dex files define Lcom/google/ads/AdRequest$ErrorCode;

    Because this error ?

    • cherryapp

      remove old jar

  • Neil

    I can not get this going for love or money . has anyone got a working demo please
    I am using eclipse juno and can not get the hang of adding admob
    All I get is errors .

  • itechaleart

    Yaa, it’s working and superb demo, its really so easy for understating.

  • Paweł Lewiński

    Hello, great tutorial which worked for me. I have a question what changes can I make to have the small banner only, without interstitial? Thanks in advane.

    • Vamsi Challa

      Use code only related to Banner Ads from the above example

  • asdssa

    I really love you Thank you very much really really Thank you

  • Govind Bhanushali

    I followed the same steps and did all as step by step, but i can not see any ads in banner. and for interstitial, it never showing ads. Please suggest where i am doing wrong, the code is completly the same as above. i can see the sessions and all in adMob site report too. but banner is not coming with any ads. it simply grey blank banner

    • sd vipeen

      Did u switch on internet connection in ur mob.?
      bcas even i had the same prob..

  • Vivek Gandhi

    Does AdMob work properly in JellyBean? I was able to load Ads in IceCream Sanwich and Kitkat, but not in jellybean. Someone please advice me

  • Onwuasoanya Ndubuisi George

    Worked perfectly. This is fantastic.

  • pakistantutor

    It did not work for me.
    I see some unknown errros in MainActivity
    Android Manifest and others

    • AndroidBegin

      Hi, could you please paste your errors on for us to have a look at your issue? Thanks :)

  • suresh

    Thanx buddy. It really helped.

  • Junico Rudyanto

    how about its?
    + no error
    + google-play-services_lib ” Done ”
    + using eclipse juno..
    – undetect google play service in library

    i have to follow your code about .xml, .java, & android manifest but but the ad has still not shown

    • Guest

      Right click on Google plays services lib project -> android.
      Click on “as library” then try to readded it to your project.

      • Junico Rudyanto

        resolved thanks :)

    • Lê Mạnh Huy

      Right click on Google plays services lib project -> properties -> android.
      Click on “as library” then try to readded it to your project.

  • Łukasz Żymła

    Hi, great tutorial, many thanks, but i have a questions.
    My app must be in play store to have a statistic? Beacuse I add my own add id and it’s show with Your code, but in admob account i don’h have any stats.

    • Łukasz Żymła

      sorry, now i have stats, they show after 24h

  • LoKey

    Hi, I am tying to incorporate this in my Java fragment extended class.. The code below: interstitial = new InterstitialAd(HomeFragment.this);
    is giving me this error message:
    The constructor InterstitialAd(HomeFragment) is undefined……

    Do you know why?

    • MattyDeBie

      try interstitial = new InterstitalAd( getActivity() );

  • manideep

    I have tried the same example by replacing interstitial.setAdUnitId(“ca-app-pub-123456789/123456789″); with my id , it was throwing null pointer exception at adView.loadAd(;

  • Ajay Kumar

    Hi., can i add my account details in admob., or is it any problem., bca admob asking my CVV and expiry date also.,pls help me

    • Alexander Nowak

      It’s your credit card information

  • John Hillen

    Hello, I tried your example and getting any Warnings and a Error code 0 after loading the ad. I use the latest google service api revision 22. I have set the Ad Unit ID for interstitial in the MainActivity and the Ad Unit ID in the main_activity.xml and copied the number for the test device from LogCat. But for all times no Ads are loaded.

    Additional I tried the google play service from your example, but with the same error.

    Tested on:
    Nexus4 – Android 5.0.1

  • Vamsi Challa

    Easy and precise as it should be.. Nice!!!

  • Terrence Markle

    Hello All… This was a very good tutorial. However, I am having a problem. I have copied the, activity_main.xml, and AndroidManifest.xml (minSdk=9 and targetSdk=19) directly into the Eclipse project “NewAdmobTutorial” as presented in this tutorial and checked all the code. When I run the project (Run -> Run As -> Android Application), I get the error “Android library projects cannot be launched”. I Google searched for a solution but nothing worked. I used the Android SDK Manager to install Google Play Services (Rev. 22) and imported the “google-play-services.jar” into the Eclipse project as an Android Private Libraries.The “is Library” box is checked in the project’s Property -> Android -> Library. I checked the Java Build Path and (1) in the Order and Export section the Android Private Libraries box is checked and (2) in the Libraries section the google-play-services.jar is included in the Android Dependencies and Android Private Libraries. I do not know what to try next. I hope someone can provide a solution for me.

    • AndroidBegin

      Hi Terrence, I understand your frustration. Before you try this tutorial, you have to know how to import libraries and configure your project properties. Copy and paste might work sometimes. I suggest you start with some of our less complicated tutorials. :)

      • Terrence Markle

        Hi AndroidBegin,… Thank you for your response. Yes, I am frustrated. I’ve been trying to get the Admob feature working for about a week.
        1. I followed all of Google’s docs for installing the Google Play Services Library using the Android SDK Manager in Eclipse IDE.
        2. I setup your project (Integrating New Google Admob…) by manually typing each line of code into Eclipse (no errors encountered).
        3. I imported the google-play-services.jar (as an Android Private Library) into the project.
        4. I checked the Java Build Path and it looks OK.
        5. When I ticked (check marked) the “is Library” box in the Property/Android/Library and tried to run the project, I got the error “Android library project cannot be launched”.
        6. When I removed the tick mark in “is Library” and tried to run the project, Eclipse displayed “Process system isn’t responding”.
        7. Question #1: Should the “is Library” box be ticked or not ticked?
        8. Question #2: Where do I find the tutorial that you mentioned that will help me solve this problem? I appreciate any help you can give me.
        Best regards,

        • Wajid Ali

          dear Sir I have same problem.. but can’t find Solution…. when I run the Project then error show :(

  • Wajid Ali

    any body can post the complete project of Admob…?

  • William Ferguson

    Please stop telling people to call from onAdLoaded(). It will get their Admob accounts banned.

    • AndroidBegin

      Hi William Ferguson, could you please elaborate more on your comment? or maybe some references? Thank you

      • William Ferguson

        Admob has always said that interstitial ads should be shown at a natural break point in your app. Showing them when the ad has finished loading means that you have no control over when they will be shown. Typically it will be 10-40 seconds after you called load() which means that the user gets interrupted in the middle on their task – perhaps the game they are playing. It is *very* poor UX and Admob regularly bans accounts for exactly this practice. I’m speaking with some good understanding of the issue as I am a Google Developer Expert for Admob.

        • AndroidBegin

          Thank you for your time and its my pleasure to welcome you to my blog. I will make sure this valuable comment being noted by all developers that visited this tutorial. Thanks and regards.


          Hello willian , i see u have experience on google ads, can u please write me on email an teach how to add interstitital ads on start and exit of my android app, i’m new and step by step guide will be very helpful to me ::D

          • William Ferguson

            An ad on exit will be extremely difficult to pull off, and an ad on start will not be the best user experience because it takes takes for the ad to load. You are better off finding a natural break point in your app. If your app doesn’t have one, then I would suggest that interstitials are not a good option for your app.

          • DanielVAVAVAVAVAVAVAVA

            i want interstitial add to show 3 sec after user enters on my appliccation, becuse its not a game and i dont have or something like that, if you help me to implement my interstitial ad on my project i will be very thankfull :D step by step guide, i saw the examples in google develope but its not what i search for:D than you

  • Vikas Dhiman

    One suggestion, better to use Android Studio for your future tutorials.


      shut the fuck up. I m using libgdx on eclipse and this works for me

  • anusha pavan kumar

    this code is not working
    i tried many times
    another code is working
    but in android 5.01 which code is working
    can any one tell pls