Integrate Third-Party Ad Networks on Android

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.

We recommend that you integrate adapters from Maven Central 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 AARs include 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.

  1. 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.

  2. Open the gradle window in Android Studio and from the Network folder, select TasksBuildBuild.

    You can find the manually built AAR under ProjectNetworkbuildoutputsaar.

  3. Incorporate the aar from Step 2 into your project by adding the .aar file to the libs directory, if your gradle dependencies file has a rule of the form:

    implementation fileTree(dir: 'libs', include: '*.aar')

    Or you can use FileNewModuleImport jar/aar to create a module in your app for the .aar. In the file dialog, navigate to the build/outputs/aar directory 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 aar module just created.

  4. Incorporate third-party SDKs into your project. This typically requires adding the network’s SDK .jar file to a libs directory, or adding its Gradle dependency (if available). You can usually find this information on the ad network’s support page.

  5. In the Publisher UI Networks tab, set up the corresponding network campaigns and target the proper ad units. Refer to our Networks tab documentation for more detail.

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.

  1. 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)
  2. Similarly, create ad renderers for third-party ad networks.

    • Google: Starting with the release of the Google native ad adapters, the GooglePlayServicesAdRenderer instance requires the dedicated GooglePlayServicesViewBinder for compatibility with Google’s MediaView:

      final GooglePlayServicesAdRenderer googlePlayServicesAdRenderer = new GooglePlayServicesAdRenderer(
          new GooglePlayServicesViewBinder.Builder(R.layout.native_video_layout)
              .mediaLayoutId( // bind to your `com.mopub.nativeads.MediaLayout` element
    • Facebook:

      FacebookAdRenderer facebookAdRenderer = new FacebookAdRenderer(
          new FacebookAdRenderer.FacebookViewBinder.Builder(R.layout.native_ad_list_item)
              .advertiserNameId( // Bind either the titleId or advertiserNameId depending on the FB SDK version

      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 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 FacebookTemplateRenderer discussed above with MoPub’s manual native ad integration (MoPubNative), because of layout issues caused by using the Ad Placer (MoPubRecyclerAdapter, MoPubStreamAdPlacer, or MoPubAdAdapter). You may notice an irregular layout of assets when using the FacebookTemplateRenderer in conjunction with the MoPub Ad Placer. This behavior has been confirmed by the Facebook Audience Network team.

    • Pangle: Pangle uses a dedicated PangleAdViewBinder that wraps the regular ViewBinder created above. Register the Pangle renderer as shown:

        final PangleAdRenderer pangleAdRenderer = new PangleAdRenderer(
                new PangleAdViewBinder.Builder(R.layout.native_ad_pangle_list_item)
                        .mediaViewIdId( // Bind to <com.bytedance.sdk.openadsdk.adapter.MediaView /> in XML
    • Mintegral:

         final MintegralAdRenderer mintegralAdRenderer = new MintegralAdRenderer(
                 new MintegralAdRenderer.ViewBinder.Builder(R.layout.native_ad_list_item)
  3. Finally, register your ad renderers, as shown below. Your classThatRegistersAdRenderers varies depending on which native ad integration you are using. Remember to register your MoPubStaticNativeAdRenderer instance last.

    // MoPubRecyclerAdapter
    MoPubRecyclerAdapter classThatRegistersAdRenderers = new MoPubRecyclerAdapter(...);
    // MoPubStreamAdPlacer
    MoPubStreamAdPlacer classThatRegistersAdRenderers = new MoPubStreamAdPlacer(...);
    // MoPubAdAdapter
    MoPubAdAdapter classThatRegistersAdRenderers = new MoPubAdAdapter(...);
    // MoPubNative
    MoPubNative classThatRegistersAdRenderers = new MoPubNative(...);

Last updated August 28, 2021

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.

© 2021 MoPub (a division of Twitter, Inc.)