AdMob Mediation SDK (Android)
Overview
We have 3 part to integrate Appier Mobile SDK through AdMob Mediation SDK for Android
- Ad Server Setting
- Integrating Appier Mobile SDK
- Enabling Test Ads
- GMA Next-Gen SDK Integration (If using GMA Next-Gen SDK)
Current Support Ad Format
- Native Ads
- Native Video Ads
- Banner Ads
- Interstitial Ads
Using GMA Next-Gen SDK?Appier AdMob Mediation supports the GMA Next-Gen SDK from version 2.4.0, for native and banner ads. See 3. GMA Next-Gen SDK Integration.
1. Ad Server Setting
Step 1 - Ad Unit Setting
- Get AdMob Ad unit ID for the App
You will need the ad unit ID from AdMob and place it in the Android App. To find out your ad unit ID, go to ad unit page and get the ad unit ID.
Note: This is NOT the ad unit id from Appier.
Step 2 - Line item for Appier Mediation
- 2.1 Setup your mediation group
In the Mediation page, please click CREATE MEDIATION GROUP button if you did not have mediation group
Choose your ad format and Select Android platform. After finish the setting, click CONTINUE button.
Fill in the mediation group name and add your ad units in the Ad units block. After add your ad unit in the Ad units block, the Ad sources block will appear.
- 2.2 Setup custom event
Click ADD CUSTOM EVENT and set your label for Appier custom event. Also, use the price you discussed with Appier Partnership team to set the eCPM.
After all the setting ready, click CONTINUE.

Next, we should set up custom event class name and parameter.
Choose the Class Name by ad format and the Google Mobile Ads SDK your app uses:
| Class Name | Format | Legacy GMA SDK | GMA Next-Gen SDK |
|---|---|---|---|
com.appier.mediation.admob.ads.AppierNativeAdapter | Native (image and video) | ✅ 2.3.0+ | ✅ 2.4.0+ |
com.appier.mediation.admob.ads.AppierBannerAdapter | Banner | ✅ 2.4.0+ | ✅ 2.4.0+ |
com.appier.mediation.admob.ads.AppierNative | Native (image only) | ✅ | ❌ |
com.appier.mediation.admob.ads.AppierBanner | Banner | ✅ | ❌ |
com.appier.mediation.admob.ads.AppierInterstitial | Interstitial | ✅ | ❌ |
A line item's class name applies to every version of your appBefore you change an existing line item to
AppierNativeAdapterorAppierBannerAdapter, make sure every live version of your app uses an Appier SDK version that includes it (see the table above), or use new ad units for the updated app versions.
For parameter, fill in the json {"zoneId": "<your_zone_id>"}, where zoneId is provided by Appier.
Click DONE when you finish the setting.
After you finish all of the mediation group setting, you can click SAVE and integrate your Android app with Appier Mobile SDK.
2. Integrating Appier Mobile SDK
In the previous section, we went through the setup of AdMob web UI. I believe you've already had at least one ad unit ID. In this section, we will focus on how to integrate Appier's SDK and start monetizing your app.
Using GMA Next-Gen SDK?Follow 3. GMA Next-Gen SDK Integration instead. It lists which steps of this section still apply.
Steps Overview
- Prerequisites
- Gradle Configuration
- AdMob Dependency
- Appier Dependencies
- Manifest Configuration
- GDPR Consent
- Ad Format Integration
- Native Ads Integration
- Banner Ads Integration
- Interstitial Ads Integration
Github Repository
Our SDK source is open-source on GitHub: appier/admob-android-mediation.
Step 1 - Prerequisites
- Make sure you are using AdMob Android SDK version >= 25.3.0
- Make sure your app's API level >= 23
Step 2 - Gradle Configuration
2.1 - AdMob Dependency
Please add google to your repositories, and specify AdMob's dependency
repositories {
// ...
google()
}
dependencies {
// AdMob SDK
implementation 'com.google.android.gms:play-services-ads:25.3.0'
}2.2 - Appier Dependencies
Please add mavenCentral to your repositories, and specify Appier's dependencies.
repositories {
// ...
mavenCentral()
}
dependencies {
// ...
implementation 'com.appier:ads-android:2.4.0'
implementation 'com.appier:ads-admob-mediation:2.4.0'
}Step 3 - Manifest Configuration
To prevent your app from crashing, following are the recommended manifest configurations.
<manifest ...>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- Required for displaying floating window -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<application
...
android:networkSecurityConfig="@xml/network_security_config">
<uses-library android:name="org.apache.http.legacy" android:required="false" />
<!-- [AdMob] Application ID -->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-xxxxxxxxxxxxxxxx~yyyyyyyyyy"/>
</application>
</manifest>You also need to add xml/network_security_config.xml into resources.
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<base-config cleartextTrafficPermitted="true" />
</network-security-config>Step 4 - GDPR Consent (Recommended)
In consent to GDPR, we strongly suggest the consent status to our SDK via Appier.setGDPRApplies() so that we will track user's personal information. Without this configuration, Appier will NOT apply GDPR by default. Note that this will impact advertising performance thus impacting revenue.
import com.appier.ads.Appier;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// ...
Appier.setGDPRApplies(true);
}
}Step 5 - Ad Format Integration
Overview
- 5.1 - Native Ads
- 5.2 - Banner Ads
- 5.3 - Interstitial Ads
5.1 - Native Ads Integration
Starting with version 2.3.0, Appier supports native image and native video ads through AdMob mediation. Both formats use the same ad-loading flow. Your layout should include an ImageView for static images and a MediaView for video.
Before loading ads, configure the Appier native mediation entry with:
- Class Name: com.appier.mediation.admob.ads.AppierNativeAdapter
- Parameter: {"zoneId": "<your_zone_id_from_appier>"}
Use the AdMob ad unit ID in your app. The Appier zone ID is configured in the mediation parameter.
Native video requires AppierNativeAdapter.
The legacy com.appier.mediation.admob.ads.AppierNative entry does not support native video.
Prepare Ad View
Create res/layout/template_admob_native_ad.xml using com.google.android.gms.ads.nativead.NativeAdView as the root.
The following layout places the static image and video in the same media area. Only one is displayed at a time. You can customize the layout to match your app.
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.nativead.NativeAdView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="8dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ad" />
<ImageView
android:id="@+id/native_privacy_information_icon_image"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="end"
android:contentDescription="Privacy information"
android:padding="8dp" />
<ImageView
android:id="@+id/native_icon_image"
android:layout_width="56dp"
android:layout_height="56dp"
android:contentDescription="Advertiser icon" />
<TextView
android:id="@+id/native_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold" />
<TextView
android:id="@+id/native_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="182dp">
<ImageView
android:id="@+id/native_main_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Ad image"
android:scaleType="centerCrop"
android:visibility="gone" />
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/native_media_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</FrameLayout>
<Button
android:id="@+id/native_cta"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</com.google.android.gms.ads.nativead.NativeAdView>All native ad assets should remain inside the NativeAdView. Register the MediaView before calling setNativeAd(). For more details, see Google's Display a native ad guide.
Load Ad
The following example loads a native ad into a ViewGroup container in your Fragment's layout.
Keep references to the loaded NativeAd and NativeAdView so they can be released when replaced or when the Fragment's view is destroyed. Ads returned by an outdated request are destroyed immediately.
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import com.google.android.gms.ads.AdLoader;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdView;
// Fields in your Fragment.
private NativeAd currentNativeAd;
private NativeAdView currentNativeAdView;
private int currentLoadGeneration;
// Call loadNativeAd(mAdContainer) after creating the Fragment's view.
private void loadNativeAd(ViewGroup adContainer) {
Context context = getContext();
View fragmentView = getView();
if (context == null || fragmentView == null) {
return;
}
final int loadGeneration = ++currentLoadGeneration;
releaseCurrentAd();
adContainer.removeAllViews();
final String adUnitId = "<your_ad_unit_id_from_admob>";
AdLoader adLoader = new AdLoader.Builder(context, adUnitId)
.forNativeAd(nativeAd -> {
// Ignore results from an outdated request or destroyed view.
if (loadGeneration != currentLoadGeneration
|| !isAdded()
|| getView() != fragmentView) {
nativeAd.destroy();
return;
}
releaseCurrentAd();
adContainer.removeAllViews();
NativeAdView adView = (NativeAdView) getLayoutInflater()
.inflate(
R.layout.template_admob_native_ad,
adContainer,
false
);
currentNativeAd = nativeAd;
currentNativeAdView = adView;
populateUnifiedNativeAdView(nativeAd, adView);
adContainer.addView(adView);
})
.build();
adLoader.loadAd(new AdRequest.Builder().build());
}Destroy Ad
Destroy the current ad and its view when they are no longer needed. Before destroying the Fragment's view, invalidate pending requests so any ads returned afterward are also released.
private void releaseCurrentAd() {
if (currentNativeAd != null) {
currentNativeAd.destroy();
currentNativeAd = null;
}
if (currentNativeAdView != null) {
currentNativeAdView.destroy();
currentNativeAdView = null;
}
}
@Override
public void onDestroyView() {
currentLoadGeneration++;
releaseCurrentAd();
super.onDestroyView();
}Populate Ad Assets
Register the asset views with NativeAdView, including the MediaView, before calling setNativeAd().
For Appier native ads, getImages() contains different assets depending on the format:
| Format | Image assets |
|---|---|
| Native image | Privacy information icon at index 0, main image at index 1 |
| Native video | Privacy information icon at index 0; video is rendered through MediaView |
The Google native ad wrapper may expose Appier's video view without returning MediaContent. The following example therefore uses the single-image asset list as a fallback when identifying Appier video ads. This fallback should not be applied to other ad sources.
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.appier.mediation.admob.AppierAdapterConfiguration;
import com.google.android.gms.ads.nativead.MediaView;
import com.google.android.gms.ads.nativead.NativeAd;
import com.google.android.gms.ads.nativead.NativeAdView;
import java.util.List;
private void populateUnifiedNativeAdView(
NativeAd nativeAd,
NativeAdView adView
) {
TextView headlineView = adView.findViewById(R.id.native_title);
TextView bodyView = adView.findViewById(R.id.native_text);
TextView ctaView = adView.findViewById(R.id.native_cta);
ImageView iconView = adView.findViewById(R.id.native_icon_image);
ImageView imageView = adView.findViewById(R.id.native_main_image);
ImageView privacyView = adView.findViewById(
R.id.native_privacy_information_icon_image
);
MediaView mediaView = adView.findViewById(R.id.native_media_view);
adView.setHeadlineView(headlineView);
adView.setBodyView(bodyView);
adView.setCallToActionView(ctaView);
adView.setIconView(iconView);
adView.setImageView(imageView);
adView.setMediaView(mediaView);
headlineView.setText(nativeAd.getHeadline());
bodyView.setText(nativeAd.getBody());
bodyView.setVisibility(
nativeAd.getBody() != null ? View.VISIBLE : View.GONE
);
ctaView.setText(nativeAd.getCallToAction());
ctaView.setVisibility(
nativeAd.getCallToAction() != null ? View.VISIBLE : View.GONE
);
if (nativeAd.getIcon() != null) {
iconView.setImageDrawable(nativeAd.getIcon().getDrawable());
iconView.setVisibility(View.VISIBLE);
} else {
iconView.setVisibility(View.GONE);
}
// Hide both until the appropriate media asset is selected.
imageView.setVisibility(View.GONE);
mediaView.setVisibility(View.GONE);
privacyView.setVisibility(View.GONE);
List<NativeAd.Image> images = nativeAd.getImages();
boolean isAppier = AppierAdapterConfiguration.getAdvertiserName()
.equals(nativeAd.getAdvertiser());
if (isAppier) {
adView.setAdvertiserView(privacyView);
if (images != null && !images.isEmpty()) {
privacyView.setImageDrawable(images.get(0).getDrawable());
privacyView.setVisibility(View.VISIBLE);
}
boolean hasVideo = nativeAd.getMediaContent() != null
&& nativeAd.getMediaContent().hasVideoContent();
// Appier-specific fallback when MediaContent is unavailable.
hasVideo = hasVideo || (images != null && images.size() == 1);
if (hasVideo) {
mediaView.setVisibility(View.VISIBLE);
} else if (images != null && images.size() > 1) {
imageView.setImageDrawable(images.get(1).getDrawable());
imageView.setVisibility(View.VISIBLE);
}
} else {
// Standard media rendering for other native ad sources.
if (nativeAd.getMediaContent() != null) {
mediaView.setMediaContent(nativeAd.getMediaContent());
mediaView.setVisibility(View.VISIBLE);
} else if (images != null && !images.isEmpty()) {
imageView.setImageDrawable(images.get(0).getDrawable());
imageView.setVisibility(View.VISIBLE);
}
}
adView.setNativeAd(nativeAd);
adView.setVisibility(View.VISIBLE);
}Your app only needs to register and display the MediaView. It does not need to create a video player or manually start playback.
5.2 - Banner Ads Integration
Appier banner ads are served through AppierBannerAdapter (2.4.0 and later). In the AdMob mediation group, configure the Appier custom event with:
- Class Name:
com.appier.mediation.admob.ads.AppierBannerAdapter - Parameter:
{"zoneId": "<your_zone_id_from_appier>"}
Already integrated withAppierBanner?
AppierBannerstill works in 2.4.0, but it is deprecated and will be removed in a future release. We recommend migrating toAppierBannerAdapter. See Migrating from AppierBanner.
Prepare Ad View
Define the adSize and adUnitId of the AdView:
<com.google.android.gms.ads.AdView
android:id="@+id/admob_banner_ad"
android:layout_width="300dp"
android:layout_height="250dp"
ads:adSize="MEDIUM_RECTANGLE"
ads:adUnitId="<your_ad_unit_id_from_admob>">
</com.google.android.gms.ads.AdView>Load Ad
No Appier-specific code is needed in the request:
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
AdView adView = findViewById(R.id.admob_banner_ad);
adView.loadAd(new AdRequest.Builder().build());The Appier banner uses the adSize of the AdView. To request a different size from Appier, pass the width and height with addNetworkExtrasBundle:
import android.os.Bundle;
import com.appier.ads.common.AppierDataKeys;
import com.appier.mediation.admob.ads.AppierBannerAdapter;
Bundle extras = new Bundle();
extras.putInt(AppierDataKeys.AD_WIDTH_LOCAL, 320);
extras.putInt(AppierDataKeys.AD_HEIGHT_LOCAL, 480);
adView.loadAd(new AdRequest.Builder()
.addNetworkExtrasBundle(AppierBannerAdapter.class, extras)
.build());Values set in the line item's Parameter field take precedence over request extras.
Destroy Ad
Call adView.destroy() when the banner is no longer needed.
Migrating from AppierBanner
- In your app, remove
addCustomEventExtrasBundle(AppierBanner.class, localExtras)from the ad request. If you need Appier to use a size different from theAdView's, pass the width and height withaddNetworkExtrasBundle(AppierBannerAdapter.class, extras)instead. - In AdMob, change the line item's Class Name from
AppierBannertoAppierBannerAdapter.
Change the class name only after your app update is liveA line item's class name applies to every app version that requests the ad unit. App versions with
ads-admob-mediationolder than 2.4.0 cannot load Appier ads from a line item that usesAppierBannerAdapter. Change it once every live version of your app uses 2.4.0 or later, or use new ad units for the updated app versions.
Legacy integration (AppierBanner)
For apps still configured with AppierBanner. Width and height are optional and default to the AdView's ad size:
import com.appier.ads.common.AppierDataKeys;
import com.appier.mediation.admob.ads.AppierBanner;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
Bundle localExtras = new Bundle();
localExtras.putInt(AppierDataKeys.AD_WIDTH_LOCAL, 300);
localExtras.putInt(AppierDataKeys.AD_HEIGHT_LOCAL, 250);
AdView adView = findViewById(R.id.admob_banner_ad);
adView.loadAd(new AdRequest.Builder()
.addCustomEventExtrasBundle(AppierBanner.class, localExtras)
.build());5.3 - Interstitial Ads Integration
To render Appier's interstitial ads via AdMob mediation, you need to specify the width and height of ad unit to load ads with suitable sizes. You can either pass through localExtras or serverExtras.
Bundle localExtras = new Bundle();
localExtras.put(AppierDataKeys.AD_WIDTH_LOCAL, 320);
localExtras.put(AppierDataKeys.AD_HEIGHT_LOCAL, 480);
InterstitialAd interstitialAd = new InterstitialAd(context);
interstitialAd.setAdUnitId("<your_ad_unit_id_from_admob>");
// Load Ad
mInterstitialAd.loadAd(new AdRequest.Builder()
.addCustomEventExtrasBundle(AppierInterstitial.class, mLocalExtras)
.build());Enable Testing Mode
To make developers test the SDK integration easily, you can enable test mode globally via Appier.setTestMode. In test mode, Appier SDK by default will force bid. You can also set to different Appier.TestMode to ensure SDK's behavior.
import com.appier.ads.Appier;
Appier.setTestMode(true); // Always get sample ads. Same as Appier.TestMode.BID
Appier.setTestMode(false); // Turn off testMode. Same as Appier.TestMode.FALSE.
Appier.setTestMode(Appier.TestMode.FALSE);
Appier.setTestMode(Appier.TestMode.BID);
Appier.setTestMode(Appier.TestMode.NO_BID);3. GMA Next-Gen SDK Integration
Appier AdMob Mediation supports the GMA Next-Gen SDK from version 2.4.0. Set up the Next-Gen SDK by following Google's Migrate to GMA Next-Gen SDK guide (or the Quick start for a new app). This section covers only what differs for Appier.
These parts of Section 2 apply unchanged:
- Step 3 – Manifest Configuration: the permissions and
network_security_config.xml. For the AdMob app ID, follow Google's guide, which moves it intoInitializationConfig. - Step 4 – GDPR Consent
- Enable Testing Mode
Supported formats on GMA Next-Gen SDK
| Format | Supported | Class Name |
|---|---|---|
| Native (image and video) | ✅ | AppierNativeAdapter |
| Banner | ✅ | AppierBannerAdapter |
| Interstitial | ❌ | — |
Step 1 - Prerequisites
- Appier
ads-androidandads-admob-mediation2.4.0 or later. - GMA Next-Gen SDK, with the minimum and compile API levels Google requires. See Set the minimum and compile Android API levels in Google's migration guide. Appier 2.4.0 was tested with
ads-mobile-sdk1.5.0. - Your AdMob line items use
AppierNativeAdapterorAppierBannerAdapter.AppierNative,AppierBannerandAppierInterstitialcannot load on GMA Next-Gen SDK.
Step 2 - Gradle Configuration
repositories {
google()
mavenCentral()
}
dependencies {
// GMA Next-Gen SDK: use the version from Google's guide
implementation 'com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk:<version>'
// Appier
implementation 'com.appier:ads-android:2.4.0'
implementation 'com.appier:ads-admob-mediation:2.4.0'
}
Exclude the legacy GMA SDK
ads-admob-mediationdepends on the legacy GMA SDK (play-services-ads), like other AdMob mediation adapters. Exclude it from your app as described in Google's Exclude com.google.android.gms modules in mediation integrations. Otherwise the build fails with duplicate class errors.
No extra ProGuard/R8 rules are needed. ads-admob-mediation ships the consumer rules it needs for GMA Next-Gen SDK.
Step 3 - Initialize GMA Next-Gen SDK
GMA Next-Gen SDK must be initialized before you load ads. Wait for the initialization completion callback before you send the first request, so the Appier adapter is ready. See Initialize GMA Next-Gen SDK in Google's guide.
Step 4 - Native Ads
Load and render native ads as described in Google's Native ads guide. No Appier-specific code is needed in the request. For Appier ads on GMA Next-Gen SDK:
- Image and video: add a
MediaViewto yourNativeAdViewand register it withregisterNativeAd(nativeAd, mediaView). It renders either the main image or the video.getImage()returns the main image. - Privacy icon: GMA draws Appier's privacy icon as AdChoices content in a corner of the ad. Do not render it yourself. To choose the corner, use
NativeAdRequest.Builder.setAdChoicesPlacement. - Identifying Appier ads: same as legacy GMA.
nativeAd.getAdvertiser()equalsAppierAdapterConfiguration.getAdvertiserName().
Step 5 - Banner Ads
Load banner ads as described in Google's Banner ads guide. No Appier-specific code is needed in the request.
The Appier banner uses the AdSize of the request. To request a different size from Appier, pass the width and height with putAdSourceExtrasBundle:
import android.os.Bundle;
import com.appier.ads.common.AppierDataKeys;
import com.appier.mediation.admob.ads.AppierBannerAdapter;
import com.google.android.libraries.ads.mobile.sdk.banner.AdSize;
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRequest;
Bundle extras = new Bundle();
extras.putInt(AppierDataKeys.AD_WIDTH_LOCAL, 320);
extras.putInt(AppierDataKeys.AD_HEIGHT_LOCAL, 480);
BannerAdRequest request = new BannerAdRequest.Builder(
"<your_ad_unit_id_from_admob>", AdSize.MEDIUM_RECTANGLE)
.putAdSourceExtrasBundle(AppierBannerAdapter.class, extras)
.build();Values set in the line item's Parameter field take precedence over request extras.
Call adView.destroy() when the banner is no longer needed. See Google's Banner ads guide for the full AdView lifecycle.
Step 6 - Migrating an Existing Integration
If your app already serves Appier ads through the legacy GMA SDK, update your AdMob line items:
| Current Class Name | Change to |
|---|---|
AppierNative | AppierNativeAdapter |
AppierBanner | AppierBannerAdapter |
AppierInterstitial | No GMA Next-Gen equivalent |
Mediation groups apply to every version of your appA line item's class name applies to every app version that requests the ad unit, including versions already in your users' hands.
AppierBannerAdapterexists only inads-admob-mediation2.4.0 and later, so app versions with an older Appier SDK cannot load Appier ads from a line item that uses it. Other ad sources in the mediation group are not affected.Before you change a class name, do one of the following:
- Make sure every live version of your app uses
ads-admob-mediation2.4.0 or later (2.3.0 or later forAppierNativeAdapter), or- Use new ad units for your GMA Next-Gen app versions, with their own mediation group that uses the new class names.
Updated 15 days ago
