AdMob Mediation Guide - uc-union/union-ads-sdk-demo GitHub Wiki

Introduction

For more details please visit Google AdMob official site

Integration Guide

Download Google Repository

SDK Manager

SDK Manager

In the Android SDK Manager window,select Extras> Google Repository, and click on Install Packages start to download after accepting the license agreement。If the Install Packages button cannot be used,don't worry. It means you have the latest version already. You don't need to take any action in SDK Manger.

Android Studio (Highly recommended)

Add dependencies dependency (usually defined in app/build.gradle), more details in app/build.gradle

dependencies {
    compile 'com.google.android.gms:play-services-ads:9.0.0'
}

Eclipse

Note: if you use Android Studio,you can skip this section.

  1. Import the content under <android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/ into current project.

  2. Add the following content to AndroidManifest.xml

    <!-- Include required permissions for Google Mobile Ads to run-->
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    
    <application android:label="@string/app_name" >
        ...
        <!--This meta-data tag is required to use Google Play Services.-->
        <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
        <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout
                                   |uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    </application>
  3. Add the following content to proguard.pro

    -keep class * extends java.util.ListResourceBundle {
        protected java.lang.Object[][] getContents();
    }
    
    # Keep SafeParcelable value, needed for reflection. This is required to support backwards
    # compatibility of some classes.
    -keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
        public static final *** NULL;
    }
    
    # Keep the names of classes/members we need for client functionality.
    -keep @interface com.google.android.gms.common.annotation.KeepName
    -keepnames @com.google.android.gms.common.annotation.KeepName class *
    -keepclassmembernames class * {
        @com.google.android.gms.common.annotation.KeepName *;
    }
    
    # Needed for Parcelable/SafeParcelable Creators to not get stripped
    -keepnames class * implements android.os.Parcelable {
        public static final ** CREATOR;
    }
    
    # Needed when building against pre-Marshmallow SDK.
    -dontwarn android.security.NetworkSecurityPolicy
    
    # Keep metadata about included modules.
    -keep public class com.google.android.gms.dynamite.descriptors.** {
      public <fields>;
    }
    
    # Keep the implementation of the flags api for google-play-services-flags
    
    -keep public class com.google.android.gms.flags.impl.FlagProviderImpl {
      public <fields>; public <methods>;
    }
    

Test

Showing Test Ads

During development, it is recommended to utilize test ads to avoid generating false impressions. To enable test ads, add the HASH_ID before loading an ad:

AdRequest request =
    AdRequest.newBuilder().testDeviceId("YOUR_HASH_ID").put("YOUR_PUB").build();

YOUR_HASH_ID is printed to the logcat when you first make a request to load an ad. Example:

google-test-device-id

Snapshot For Test Ads

Once you load an ad with test device id, you should see something like this:

  • Banner

    google-test-banner-example

  • Interstitial

    google-test-interstitial-example

Next Steps

⚠️ **GitHub.com Fallback** ⚠️