AdMob Mediation Guide - uc-union/union-ads-sdk-demo GitHub Wiki
For more details please visit Google AdMob official site
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.
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'
}
Note: if you use Android Studio,you can skip this section.
-
Import the content under
<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/
into current project. -
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>
-
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>; }
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:
Once you load an ad with test device id, you should see something like this:
-
Banner
-
Interstitial
- Follow our guide on Initialize SDK to start sdk integration.