Code Integration for Android

Get started with Prebid Mobile by getting access to a Prebid Server. Once your account is set up include the Prebid Mobile SDK in your app by either using Maven or by cloning the repo and using our included script to build the SDK.

Include with Maven

If you are not familar with using Maven for build management visit the Maven website.

To include the Prebid Mobile SDK simply add this line to your gradle dependencies to get the lastest stable release:

implementation 'org.prebid:prebid-mobile-sdk:1.12.2'

Build framework from source

After cloning the repo, use Terminal or another command line tool, change to the root directory and run:

./buildprebid.sh

to output the PrebidMobile framework for Android.

Integrate Ad Servers With Your App

Integrating MoPub with your application

  1. Go to MoPub.com and register for a MoPub account . If you already have an account with them, you can log in.
  2. After the registration you will be automatically prompted to set up a new MoPub application required for integrating mobile ads to your application.

Integrating Google with your application

Go to Google’s developer site and follow the instructions for integrating their Mobile Ads SDK into your app.

Set Targeting Parameters (Optional)

Targeting parameters enable you to define the target audience for the bid request. Prebid Mobile supports the following global targeting parameters. These targeting parameters are set only once and apply to all Prebid Mobile ad units. They do not change for a given user session.

View the full list of targeting parameters.

Create Ad Units

Banner and interstitial ad units can be created:

BannerAdUnit bannerAdUnit = new BannerAdUnit("PREBID_SERVER_CONFIGURATION_ID", 300, 250);

For details on creating the specific ad units and additional parameters and methods associated with each view the documentation pertaining to them:

Banner Ad Unit
Interstitial Ad Unit

Using Asset Ids with In-App Native Ad Units

Setting this option to true, in your instance of Prebid Mobile, enables you to add an id for each asset in the assets array. The default setting is false

Kotlin

PrebidMobile.assignNativeAssetID(true)

Java

PrebidMobile.assignNativeAssetID(true);

Resize ad slot

Prebid recommends app developers to resize ads slots to the Prebid rendering ad size using native code due to an unresolved bug in the Google Mobile Ads SDK (described here) where render failures can occur with 3rd party creatives (such as Prebid Universal Creative) using size overrides.

dfpAdView.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        super.onAdLoaded();

        AdViewUtils.findPrebidCreativeSize(dfpAdView, new AdViewUtils.PbFindSizeListener() {
            @Override
            public void success(int width, int height) {
                dfpAdView.setAdSizes(new AdSize(width, height));
            }

            @Override
            public void failure(@NonNull PbFindSizeError error) {
                Log.d("MyTag", "error: " + error);
            }
        });

    }
});

Supported Android versions

Prebid supports the following versions by release:

  • Prebid SDK version 1.0 or 1.1 supports Android 16+
  • Prebid SDK version 1.1.1+ supports Android 19+

Further Reading