Google Admob Ads Implementation – Get Started Guide

With this guide you can monetize your android application without using fire base just implementing SDK.

Prerequisites

Import the Mobile Ads SDK

Apps can import the Google Mobile Ads SDK with a Gradle dependency that points to Google’s Maven repository. In order to use that repository, you need to reference it in the app’s project-level build.gradle file. Open yours and look for an allprojects section:

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Add the google() directive above if it’s not already present.

Next, open the app-level build.gradle file for your app, and look for a “dependencies” section.

Example app-level build.gradle (excerpt)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
}

Add the line in bold above, which instructs Gradle to pull in the latest version of the Mobile Ads SDK. Once that’s done, save the file and perform a Gradle sync.

Update your AndroidManifest.xml

Add your AdMob App ID to your app’s AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>

    </application>
</manifest>

Import the Mobile Ads SDK

Apps can import the Google Mobile Ads SDK with a Gradle dependency that points to Google’s Maven repository. In order to use that repository, you need to reference it in the app’s project-level build.gradle file. Open yours and look for an allprojects section:

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Add the google() directive above if it’s not already present.

Next, open the app-level build.gradle file for your app, and look for a “dependencies” section.

Example app-level build.gradle (excerpt)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
}

Add the line in bold above, which instructs Gradle to pull in the latest version of the Mobile Ads SDK. Once that’s done, save the file and perform a Gradle sync.

Update your AndroidManifest.xml

Add your AdMob App ID to your app’s AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>

    </application>
</manifest>

Import the Mobile Ads SDK

Apps can import the Google Mobile Ads SDK with a Gradle dependency that points to Google’s Maven repository. In order to use that repository, you need to reference it in the app’s project-level build.gradle file. Open yours and look for an allprojects section:

Example project-level build.gradle (excerpt)

allprojects {
    repositories {
        google()
        jcenter()
    }
}

Add the google() directive above if it’s not already present.

Next, open the app-level build.gradle file for your app, and look for a “dependencies” section.

Example app-level build.gradle (excerpt)

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'com.google.android.gms:play-services-ads:18.0.0'
}

Add the line in bold above, which instructs Gradle to pull in the latest version of the Mobile Ads SDK. Once that’s done, save the file and perform a Gradle sync.

Update your AndroidManifest.xml

Add your AdMob App ID to your app’s AndroidManifest.xml file by adding the <meta-data> tag shown below. You can find your App ID in the AdMob UI. For android:value insert your own AdMob App ID in quotes, as shown below.

<manifest>
    <application>
        <!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>

    </application>
</manifest>

Update Your MainActivity.java

package ...
import ...
import com.google.android.gms.ads.MobileAds;

public class MainActivity extends AppCompatActivity {
    ...
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713
        MobileAds.initialize(this, "YOUR_ADMOB_APP_ID");
    }
    ...
}



on Twitter


on Facebook


on Google+

About the author

admin

At E-Code Geeks we help people who are trying to create their own website, with the help of our easy-to-follow tutorial videos.

We created E-Code Geeks as a place where anyone can quickly and easily learn about web design – simply, by watching a video.

And also we updated life styles articles like Food, Traveling, Health for better knowledge.

It’s much simpler and it’s fast!

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *