Objective
This course provides the detailed steps on integrating the admob library with your android app. When I was integrating admob with my game app Word Puzzle Game I struggled a lot to make the ads live.
I thought of share my experience which helps some one.
Prerequisites
Make sure you have created admob account using https://admob.google.com/ and created app with ad units.
Integration Steps
1. Make sure you have following items in project level build.gradle.
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.2'
}
2. Open your app level build.gradle file and make sure you have following lines.
dependencies {
implementation 'com.google.android.gms:play-services-ads:19.1.0'
}
3. Verify permissions in android manifest xml file.
<application
android:usesCleartextTraffic="true"
...
>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!--
Below lines are optional. In logcat I saw the error message from google library
that was trying to access bluetooth api so I added below lines.
Ads started working for me in real device. But it is not guaranteed for your implementation. -->
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<!-- Make sure you provided proper app id in the strings file -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="@string/admob_appid" />
Lets see what are all the steps we need to take care on the layout and java files.