Skip to main content

Installing Google AdMob into Android Apps

Previously I wrote on why ads are needed to help maintaining an app. Read the article here

---This is quite an old article. You may find the latest supporting AdMob 6.x in here ---

This is quite a long tutorial, there are 3 major steps involved. The experiment is done using Windows 7, Eclipse Helios and AdMob SDK 4.1.0 (which currently is the latest-during time of writing).

STEP 1: Get the ads from

To display the AdMob ads in your Android mobile apps, you need to register first at the . After completing the registration, login and Add Site/App. Refer to Figure 1.


Figure 1

Choose the desired platform and fill in the details (as in Figure 2). Just put http:// in the Android Package URL if your app is not published in the market yet. And click Continue.

ScreenHunter_16 May. 16 08.35

Figure 2

Download the AdMob Android SDK, and save the zip file in your machine. Make sure to extract the file and save it to your hard disk (anywhere is possible).

ScreenHunter_17 May. 16 08.36

Figure 3

STEP 2: Install the AdMob SDK into your Android project.

The most important file in the AdMob Android SDK that you download is GoogleAdMobAdsSdk-4.1.0.jar . Currently it’s in version 4.1.0 .

ScreenHunter_18 May. 16 08.40

Figure 4

Go to your project folder (in Eclipse), and right click to your project (Figure 5). Choose Properties.


Figure 5

Click the Java Build Path on your left. Choose the Libraries in the tab, and click Add External JARs. Locate the JAR file (GoogleAdMobAdsSdk-4.1.0.jar). And click OK.


Figure 6


Figure 7


Figure 8

STEP 3: The codes to display ads in your app.

Add some additional activity and permissions in the manifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Calc"
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<activity android:name=""

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-sdk android:minSdkVersion="4" />


Create attr.xml file in the res/values 



Related links

  1. Official Documentation (which is not updated timely) -
  2. Official Discussion (AdMob SDK 4.0.10) -
  3. A very good tutorial for AdMob SDK 4.0.4 -


  1. I think that attrs.xml file is not used anymore in version 4.1.0, so it's not needed. Also setTesting method is being deprecated.

  2. Dear Anonymous,
    Thanks for the comment. I'll check and update this post later...

  3. So far the hands-on provided here is working...

  4. Hi,
    Can you take a look at the following question from ?

    I seem to get this behavior ONLY when i load the AdView in my activity. Even an empty Activity with just the AdView widget takes tons of memory and I see with HPROF that what's keeping it from being released is that the InputMethodManager holds a reference to it (Which I didn't add anywhere...)

  5. Another related question on the same memory issue:

  6. I've added the code and i'm not getting any add..
    I've changed ads:adUnitId="YOUR_PUBLISHER_ID_HERE" for ads:adUnitId="xxxxxxxxxxxxx" the x's stand for the Publisher Id.
    After waiting 4 minutes on my phone im not getting any ads?

  7. Dear Christian,

    Maybe you could share with me the project folder, I'll check it for you.
    Email me at khirulnizam[a]

  8. I found that it's not working in the emulator. You need to test the admob ads in a real Android phone.

  9. Try to add: adRequest.addTestDevice("314321C010A54CE800467089A3E155E6");
    Look for this code in LogCat while you start the app.

  10. salam kenal sob, info: buat rekan2 yang ingin pasang mobgold/admob dengan java script di halaman html silahkan kunjungi terimakasih

  11. make sure to setTesting() to false, when you deploy the apps...

    AdView adview = (AdView)findViewById(;
    AdRequest re = new AdRequest();
    re.setTesting(false);//this must be false when apps is released in the market

  12. Can you tell me how to put an ads banner in the preview screen for a live wallpaper?As in the Fireflies live wallpaper (, I don't know how to put an ads banner in the Preview screen (not Settings screen).

    When I install the Fireflies wallpaper on my HTC which is on Android 2.2.1 the banner shows up in both Preview and Settings screens, but on my two other Sony Ericsson (on 2.3.3) I can only see the banner in the Setting screens. Does that have something to do with Sony Ericsson or the version of Android?


  13. My app is telling me I need to have AdActivity declared in AndroidManifest with configChanges. but added the lines:

    Any clue what is wrong?

  14. ok so I found out that eclipse wants me to change to android:configChanges="keyboard|keyboardHidden|orientation|screenlayout|uiMode|screenSize|smallestScreenSize"/> but when I do this, it says string types not allowed.

  15. Refer to this post for AdMob SDK 6.x
    All the best...

    1. I have added this sample code to my app and it work perfect on my device, I saw my first admob ads for a brief moment in fact how many times evry time I run the app on my device but when it goes to the next activity it will not display the next screen and would totally kills the whole app. it say it stopped unexpectedly. can you help me. thanks.

  16. also in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.

  17. also in addition i saw my admob status and shows that my app is sending my request. hence the code work but am i missing something an ondistroy or any class that would display the next activity I mean it totally just wont go to the next acctivity it displays the first screen with my admob insert running and it just crash evrytime it goes to the next screen. again thanks.

  18. sorry to add this again anyway, I have a fatal error: NoAPI database founf in null comment in my error log. I guess thats what it starts but how come it works when I dont have the admob insert. do I have to include something before going to the next activity. again sir thanks a million to your help.

    1. It's difficult for me to debug the error without having to look at the source code and the error message personally...

    2. Wondering whether you install AdMob 4.x or AdMob 6.x...


Post a Comment

Popular posts from this blog

Several English proverbs and the Malay pair

Or you could download here for the Malay proverbs app – English proverbs and the Malay pair Corpus Reference: Amir Muslim, 2009. Peribahasa dan ungkapan Inggeris-Melayu. DBP, Kuala Lumpur CTRL+F to search Proverbs in English Definition in English Similar Malay Proverbs Definition in Malay 1 Where there is a country, there are people. A country must have people. Ada air adalah ikan. Ada negeri adalah rakyatnya. 2 Dry bread at home is better than roast meat home's the best hujan emas di negeri orang,hujan batu di negeri sendiri Betapa baik pun tempat orang, baik lagi tempat sendiri. 3 There's no accounting for tastes We can't assume that every people have a same feel Kepala sama hitam hati lain-lain. Dalam kehidupan ini, setiap insan berbeza cara, kesukaan, perangai, tabia

WebDev PHP DEVELOPMENT TOOLS Download the XAMPP latest version from . This installation file contains the Apache web server, PHP 5 and 4 interpreter, and the MySQL 5 Community edition. - download latest version MozillaFireFox (OpenSource web browser firefox) – download latest version Google Chrome – fastest web browser on earcth – fast download chrome here TEACHING PLAN Download the teaching plan here for Web/Internet Programming ( download ) NOTES HTML references HTML Editor - Lab 1: HTML Basics - Lab 2: Responsive Design: Lab 3: HTML Forms Lab 4: HTML 5 Lab 5: Bootstrap for responsive Web -

Contact Us at

Powered by EMF HTML Contact Form

Bootstrap Template for PHP database system - MyCompanyHR

HTML without framework is dull. Doing hard-coded CSS and JS are quite difficult with no promising result on cross platform compatibility. So I decided to explore BootStrap as they said it is the most popular web framework. What is BootStrap? - Bootstrap is the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first web sites. (   ) Available here - Why you need Flat-UI? Seems like a beautiful theme to make my site look professional. Anyway you could get variety of BootStrap theme out there, feel free to select here Flat-UI is from DesignModo - Web Programming MyCompanyHR – PHP & MySQL mini project (with Boostrap HTML framework) Template 1: Template for the Lab Exercise. This is a project sample of a staff record management system. It has the PHP structured co

Login JSON Android using Login Activity

I’ve been trying to release this tutorial quite a while. At last after a long hard effort. Since HttpClient is not supported any more in Android SDK 23, I have to resort to org.json.JSONObject and library to do online database with JSON. The objective of this tutorial is to log-in from a mobile client with the username and password stored in an online database facility. STEP 1: Create a new Android project, this time choose the LoginActivity .