Integrate Third-Party Ad Networks on Android
- Recommended: Use Our Mediation Integration Tool
- Integrate Adapters Manually via Source Code (GitHub)
- Set Up Ad Renderers for Native Ads
MoPub partners with most ad networks and supports these mediation partners with pre-built adapters. Refer to our list of supported ad networks. You can easily integrate our pre-built adapters by using the MoPub Mediation Integration Tool. You can still mediate ad networks with whom we do not partner (unsupported networks) by using third-party adapters.
Use this guide to set up mediation by downloading adapters and integrating them into your app project. There are two ways to integrate networks: through our MoPub Mediation Integration Tool (recommended), or manually via source code.
Recommended: Use Our Mediation Integration Tool
We recommend that you integrate adapters from Bintray/JCenter using our MoPub Mediation Integration Tool. This is the more efficient option if you’re just getting started with mediation, and don’t need to customize anything.
Our tool provides a new and convenient integration approach. Simply select the ad networks you want to mediate, and generate the Gradle/Cocoapods configuration required for your app setup. The mediation adapter
AndroidManifest dependencies for each ad network.
Integrate Adapters Manually via Source Code (GitHub)
If you prefer, you can still integrate adapters manually using the existing process. We have migrated our mediation adapters to a new GitHub repository.
Download the mediation repository; that is, simply clone the entire repository and open it in Android Studio. You are now ready to build
AARs using adapter source files for every network with which you want mediate.
gradlewindow in Android Studio and from the Network folder, select Tasks → Build → Build.
You can find the manually built
AARunder Project → Network → build → outputs → aar.
Incorporate the aar from Step 2 into your project by adding the
.aarfile to the
libsdirectory, if your gradle dependencies file has a rule of the form:
implementation fileTree(dir: 'libs', include: '*.aar')
Or you can use File → New → Module → Import jar/aar to create a module in your app for the
.aar. In the file dialog, navigate to the
build/outputs/aardirectory in the cloned repository, and select the
aar. Android Studio will copy it into your project. Then select the app module, right-click Open Module Settings, and add a Module Dependency on the
aarmodule just created.
Incorporate third-party SDKs into your project. This typically requires adding the network’s SDK
.jarfile to a
libsdirectory, or adding its Gradle dependency (if available). You can usually find this information on the ad network’s support page.
Set Up Ad Renderers for Native Ads
To run native ads through mediated ad networks, you must set up the native ad renderer. Create and register the appropriate renderer for each ad network to ensure that your native ad views are laid out as intended. Refer to our Networks tab documentation for more detail.
Begin with the default
MoPubStaticNativeAdRenderer, shown below:
// Some third party SDKs rely on the MoPub renderer as a default renderer. MoPubStaticNativeAdRenderer moPubStaticNativeAdRenderer = new MoPubStaticNativeAdRenderer( new ViewBinder.Builder(R.layout.native_ad_list_item) .titleId(R.id.native_title) .textId(R.id.native_text) .mainImageId(R.id.native_main_image) .iconImageId(R.id.native_icon_image) .callToActionId(R.id.native_cta) .privacyInformationIconImageId(R.id.native_privacy_information_icon_image) .build() );
Similarly, create ad renderers for third-party ad networks.
Google: Starting with the 188.8.131.52 release of the Google native ad adapters, the
GooglePlayServicesAdRendererinstance requires the dedicated
GooglePlayServicesViewBinderfor compatibility with Google’s MediaView:
final GooglePlayServicesAdRenderer googlePlayServicesAdRenderer = new GooglePlayServicesAdRenderer( new GooglePlayServicesViewBinder.Builder(R.layout.native_video_layout) .mediaLayoutId(R.id.native_media_layout) // bind to your `com.mopub.nativeads.MediaLayout` element .iconImageId(R.id.native_icon_image) .titleId(R.id.native_title) .textId(R.id.native_text) .callToActionId(R.id.native_cta) .privacyInformationIconImageId(R.id.native_privacy_information_icon_image) .build());
Facebook: Starting with the 4.99.0 release of the Facebook Audience Network SDK, use a dedicated
ViewBinderfor Facebook (
FacebookViewBinder), as shown:
FacebookAdRenderer facebookAdRenderer = new FacebookAdRenderer( new FacebookAdRenderer.FacebookViewBinder.Builder(R.layout.native_ad_list_item) .titleId(R.id.native_title) .textId(R.id.native_text) // Binding to new layouts from Facebook 4.99.0+ .mediaViewId(R.id.native_main_image) .adIconViewId(R.id.native_icon_image) .adChoicesRelativeLayoutId(R.id.native_ad_choices_relative_layout) .advertiserNameId(R.id.native_title) // Bind either the titleId or advertiserNameId depending on the FB SDK version // End of binding to new layouts .callToActionId(R.id.native_cta) .build());
To know which specific layout elements to use in your XML for the
AdIconView, and AdChoices
FacebookViewBinder, refer to this sample XML layout.
Starting with the 5.2.0 release of the Facebook Audience Network SDK, you can simplify your ad layout by using a pre-defined template provided by Facebook. Instead of binding to your own XML views like above, simply import and create a new
FacebookTemplateRenderer(which is a new adapter class introduced in the 184.108.40.206 release) and pass in a new
NativeAdViewAttributes()as shown below:
FacebookTemplateRenderer facebookAdRenderer = new FacebookTemplateRenderer(new NativeAdViewAttributes());
Note: At this time, we only encourage you to use the
FacebookTemplateRendererdiscussed above with MoPub’s manual native ad integration (
MoPubNative), because of layout issues caused by using the Ad Placer (
MoPubAdAdapter). You may notice an irregular layout of assets when using the
FacebookTemplateRendererin conjunction with the MoPub Ad Placer. This behavior has been confirmed by the Facebook Audience Network team.
Pangle: Pangle uses a dedicated
PangleAdViewBinderthat wraps the regular
ViewBindercreated above. Register the Pangle renderer as shown:
final PangleAdRenderer pangleAdRenderer = new PangleAdRenderer( new PangleAdViewBinder.Builder(R.layout.native_ad_pangle_list_item) .callToActionId(R.id.native_cta) .decriptionTextId(R.id.native_text) .iconImageId(R.id.native_icon_image) .titleId(R.id.native_title) .mediaViewIdId(R.id.native_main_image) // Bind to <com.bytedance.sdk.openadsdk.adapter.MediaView /> in XML .build());
Finally, register your ad renderers, as shown below. Your
classThatRegistersAdRenderersvaries depending on which native ad integration you are using. Remember to register your
// MoPubRecyclerAdapter MoPubRecyclerAdapter classThatRegistersAdRenderers = new MoPubRecyclerAdapter(...); // MoPubStreamAdPlacer MoPubStreamAdPlacer classThatRegistersAdRenderers = new MoPubStreamAdPlacer(...); // MoPubAdAdapter MoPubAdAdapter classThatRegistersAdRenderers = new MoPubAdAdapter(...); // MoPubNative MoPubNative classThatRegistersAdRenderers = new MoPubNative(...); classThatRegistersAdRenderers.registerAdRenderer(googlePlayServicesAdRenderer); classThatRegistersAdRenderers.registerAdRenderer(facebookAdRenderer); classThatRegistersAdRenderers.registerAdRenderer(pangleAdRenderer); classThatRegistersAdRenderers.registerAdRenderer(staticAdRender);
Last updated December 03, 2020
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2020 MoPub (a division of Twitter, Inc.)