Adding Ads to Android App

Adding Google’s Admob Ads to Android Studio App

If you’ve never been used Admob for advertising an App, you properly need to go first to Google’s Admob Website and sign up for an Admob account:

Creating the Ad on Admob

After logging into Admob click on
Screenshot from 2015-05-25 09:05:31

If your App is brand new, you need to choose “Add your app manually” from the tabs.

Screenshot from 2015-05-25 09:06:44

And fill in the package name. I am using for this example the app BMI Calculator from the last tutorial that has the package name “com.greendog.example.bmiapp”

Screenshot from 2015-05-25 09:11:13

Choose “Android” as platform and click on <Add app>.

Screenshot from 2015-05-25 09:17:39

Here you can choose between Banner and Interstitial Ads.

Banners are small impressions that can be customized in size. The size will be defined later in Android Studio. More info at Google Developer.

Interstitial Ads are fullscreen Ads. More info at Google Developer.

I will continue with Banners in this example and use the App BMI Calculator from this tutorial.

After clicking <Save> you will get your publisher code for this Ad. You need to copy this code (Ad unit ID).

Screenshot from 2015-05-25 09:19:03

Now head over to Android Studio. The best way to start is, to add the Ad unit ID into the strings.xml like this.

Screenshot from 2015-05-25 09:23:27

Next open the build.gradle file of your project and add the following library entry to use Admob Ads.

Screenshot from 2015-05-25 09:28:41

Now, we’re going to add the needed code to the layout file where we want to show the Ad.

There’re two parts. First, you need a second xmlms line that allows you to call adds.


Screenshot from 2015-05-25 09:34:18


The second part is the layout of the Banner itself.

Screenshot from 2015-05-25 12:45:45

I used for ad size SMART_BANNER. SMART_BANNER resizes automatically between phone and tablet size.

There are more sizes available. For more info go to Google Developer.

It is also necessary to add code to the Activity that calls this layout.


At last the AndroidManifest.xml needs som code, and configuration.part is to

The first part is to add the required permissions

Screenshot from 2015-05-25 13:02:23

Second you need to include the AdActivity

Screenshot from 2015-05-25 13:02:38

All the code snipsels can be found at the Google Developer page I mentioned earlier.

Time to run the App and check if the impressions are showing.


Looks good. Our “Money Maker” is ready to go.

In the next tutorial, I will go through the steps how to deploying the app to Google’s Play Store.

See you soon.

And don’t forget to promote your App:

For example with your own download badge, automaticly made for you by Google.

It could look like this:


Get it on Google Play