Guide for migrating to version 6

Warning

Make sure to update your used Yandex mediation adapters and adapters for third-party mediation networks to the latest version. Older versions may cause adapter integration errors that can prevent your ads from being served.

Manual initialization

Manual SDK initialization process changed. You now need to deliver the callback to the MobileAds.initialize() method when initializing the app.

MobileAds.initialize(this) {
    // Now you can use ads
}
MobileAds.initialize(this, () -> {
    // Now you can use ads
});

Banners

Renamed the AdSize class to BannerAdSize. Removed the fixedSize(int width, int height), flexibleSize(int width, int maxHeight), and stickySize(int width) methods.

Use methods depending on the ad type:

Use the BannerAdSize.stickySize(Context context, int width) method to create an adaptive sticky banner.

That is a small, automatically updated ad placed at the top or bottom of the app screen.

It does not overlap the main app content and is often used in game apps.

The height of a sticky banner is determined automatically, adapting to the screen size of the device and not taking up more than 15% of the screen height.

Warning

Version 6.0.0 added autorefresh support for adaptive sticky banners.

If you have previously implemented autorefresh for sticky banners, disable it.

To create an adaptive inline banner, use the BannerAdSize.inlineSize(Context context, int width, int maxHeight) method.

Adaptive inline banners are a flexible format of banner advertising, providing maximum efficiency by optimizing the ad size on each device.

The height of the banner is adjusted automatically and might reach the device screen height.

Typically, that format is used in feed-based apps or contexts where it's okay to focus primarily on the ad.

For backward compatibility, we added the fixedSize(Context context, int width, int height) method instead of fixedSize(int width, int height), but we don't recommend using it. Use inlineSize(Context context, int width, int maxHeight) or stickySize(Context context, int width) instead. In SDK 6.0.0, the height of the banner is calculated automatically and known before the ad request is sent. You can use this height in your screen layout.

Rewarded ads

We changed the approach to creating and loading ads. We now provide the RewardedAdLoader loader object, which loads the ads, and the RewardedAd ad object retrieved by loader callback methods from the RewardedAdLoadListener.

To learn more about the new API, see the SDK reference.

Ad loading

SDK 5

A single object for ad loading and rendering:

val rewardedAd = RewardedAd(this@Activity).apply {
    setAdUnitId("your-ad-unit-id")
    setAdEventListener(this)
    loadAd(adRequest)
}
final RewardedAd rewardedAd = new RewardedAd(this);
rewardedAd.setAdUnitId("your-ad-unit-id");
rewardedAd.setAdEventListener(this);
rewardedAd.loadAd(adRequest);

SDK 6

RewardedAdLoader for loading multiple ads: You don't need to pass the Activity context for loading ads.

Once the ad is loaded (by calling the onAdLoaded(rewardedAd: RewardedAd) method), save the link to the loaded RewardedAd before its display is completed.

val loader = RewardedAdLoader(context).apply {
    setAdLoadListener(object : RewardedAdLoadListener {
        override fun onAdLoaded(rewardedAd: RewardedAd) {
            // Save rewardedAd to a local variable
            // Now rewardedAd is ready to be shown
        }

        override fun onAdFailedToLoad(adRequestError: AdRequestError) {}
    })
}
loader.loadAd(AdRequestConfiguration.Builder("your-ad-unit-id").build())
final RewardedAdLoader loader = new RewardedAdLoader(this);
loader.setAdLoadListener(new RewardedAdLoadListener() {
    @Override
    public void onAdLoaded(@NonNull RewardedAd rewardedAd) {
        // Save rewardedAd to a local variable
        // Now rewardedAd is ready to be shown
    }

    @Override
    public void onAdFailedToLoad(@NonNull AdRequestError adRequestError) {}
});
loader.loadAd(new AdRequestConfiguration.Builder("your-ad-unit-id").build());

Ad rendering

SDK 5

Before showing the ad, see if it loaded.

if (rewardedAd.isLoaded()) {
    rewardedAd.show()
}
if (rewardedAd.isLoaded()) {
    rewardedAd.show();
}

SDK 6

You don't need to check to see if the ad is loaded.

The ad is ready for rendering after a RewardedAd instance is returned by the onAdLoaded callback method for the ad loader.

To render the ad, you need to pass Activity:

rewardedAd.show(activity)
rewardedAd.show(activity);

RewardedAd ad object

SDK 5

A class that combines ad loading and rendering.

SDK 6

Interface of a loaded ad. Added the getInfo() method for obtaining information about the ad.

interface RewardedAd {
    fun setAdEventListener(rewardedAdEventListener: RewardedAdEventListener)

    fun show(activity: Activity)

    fun getInfo(): AdInfo
}
interface RewardedAd {
    void setAdEventListener(@Nullable RewardedAdEventListener rewardedAdEventListener);

    void show(@NonNull Activity activity);

    @NonNull
    AdInfo getInfo();
}

Callback methods

SDK 5

A single callback method interface that combines event loading and rendering:

interface RewardedAdEventListener {

    fun onLoaded()

    fun onRewarded(reward: Reward)

    fun onAdFailedToLoad(adRequestError: AdRequestError)

    fun onAdShown()

    fun onAdDismissed()

    fun onLeftApplication()

    fun onReturnedToApplication()
}
interface RewardedAdEventListener {

    public void onLoaded();

    public void onRewarded(@NonNull Reward reward);

    public void onAdFailedToLoad(@NonNull AdRequestError adRequestError);

    public void onAdShown();

    public void onAdDismissed();

    public void onLeftApplication();

    public void onReturnedToApplication();
}

SDK 6

The RewardedAdEventListener interface is divided into two parts: callback methods for loading RewardedAdLoadListener and rendering RewardedAdEventListener.

Removed the onLeftApplication() and onReturnedToApplication() methods.

Added the onAdFailedToShow(AdError) method.

interface RewardedAdLoadListener {
    fun onAdLoaded(rewardedAd: RewardedAd)

    fun onAdFailedToLoad(adRequestError: AdRequestError)
}

interface RewardedAdEventListener {
    fun onAdShown()

    fun onAdFailedToShow(adError: AdError)

    fun onAdDismissed()

    fun onAdClicked()

    fun onAdImpression(impressionData: ImpressionData)

    fun onRewarded(reward: Reward)
}
interface RewardedAdLoadListener {
    void onAdLoaded(@NonNull RewardedAd rewardedAd);

    void onAdFailedToLoad(@NonNull AdRequestError adRequestError);
}

interface RewardedAdEventListener {
    void onAdShown();

    void onAdFailedToShow(@NonNull AdError adError);

    void onAdDismissed();

    void onAdClicked();

    void onAdImpression(@Nullable ImpressionData impressionData);

    void onRewarded(@NonNull Reward reward);
}

Cleaning the RewardedAd ad object

SDK 5

Call the onDestroy() method and stop keeping the ad object reference.

SDK 6

The onDestroy() method has been removed.

To clean an ad object, pass null to the function for setting a listener for rewardedAd.setAdEventListener callback methods and stop keeping the ad object reference:

private fun destroyRewardedAd() {
    rewardedAd?.setAdEventListener(null)
    rewardedAd = null
}
private void destroyRewardedAd() {
    if (mRewardedAd != null) {
        mRewardedAd.setAdEventListener(null);
        mRewardedAd = null;
    }
}

Interstitial advertising

We changed the approach to creating and loading ads. We now provide the InterstitialAdLoader loader object, which loads the ads, and the InterstitialAd ad object retrieved by the loader callback methods from the InterstitialAdLoadListener.

For more details about the new API, see the SDK reference.

Ad loading

SDK 5

A single object for ad loading and rendering:

val interstitialAd = InterstitialAd(this@Activity).apply {
setAdUnitId("your-ad-unit-id")
setAdEventListener(this)
loadAd(adRequest)
}
final InterstitialAd interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId("your-ad-unit-id");
interstitialAd.setAdEventListener(this);
interstitialAd.loadAd(adRequest);

SDK 6

InterstitialAdLoader for loading multiple ads. You don't need to pass the Activity context for loading ads.

Once the ad is loaded (by calling the onAdLoaded(interstitialAd: InterstitialAd) method), save the link to the loaded InterstitialAd before its display is completed.

val loader = InterstitialAdLoader(context).apply {
    setAdLoadListener(object : InterstitialAdLoadListener {
        override fun onAdLoaded(interstitialAd: InterstitialAd) {
            // Save interstitialAd to a local variable
            // Now interstitialAd is ready to be shown
        }

        override fun onAdFailedToLoad(adRequestError: AdRequestError) {}
    })
}
loader.loadAd(AdRequestConfiguration.Builder("your-ad-unit-id").build())
final InterstitialAdLoader loader = new InterstitialAdLoader(this);
loader.setAdLoadListener(new InterstitialAdLoadListener() {
    @Override
    public void onAdLoaded(@NonNull InterstitialAd interstitialAd) {
        // Save interstitialAd to a local variable
        // Now interstitialAd is ready to show
    }

    @Override
    public void onAdFailedToLoad(@NonNull AdRequestError adRequestError) {}
});
loader.loadAd(new AdRequestConfiguration.Builder("your-ad-unit-id").build());

Ad rendering

SDK 5

if (interstitialAd.isLoaded()) {
    interstitialAd.show()
}
if (interstitialAd.isLoaded()) {
    interstitialAd.show();
}

SDK 6

You don't need to check to see if the ad is loaded.

The ad is ready for rendering after an InterstitialAd instance is returned by the onAdLoaded callback method for the ad loader.

To render the ad, you need to pass Activity:

interstitialAd.show(activity)
interstitialAd.show(activity);

InterstitialAd ad object

SDK 5

A class that combines loading and rendering of an ad.

SDK 6

Interface of a loaded ad. Added the getInfo() method for getting information about the ad.

interface InterstitialAd {
    fun setAdEventListener(interstitialAdEventListener: InterstitialAdEventListener)

    fun show(activity: Activity)

    fun getInfo(): AdInfo
}
interface InterstitialAd {
    void setAdEventListener(@Nullable InterstitialAdEventListener interstitialAdEventListener);

    void show(@NonNull Activity activity);

    @NonNull
    AdInfo getInfo();
}

Callback methods

SDK 5

A single callback method interface that combines event loading and rendering:

interface InterstitialAdEventListener {

    fun onLoaded()

    fun onAdFailedToLoad(adRequestError: AdRequestError)

    fun onAdShown()

    fun onAdDismissed()

    fun onLeftApplication()

    fun onReturnedToApplication()
}
interface InterstitialAdEventListener {

    public void onLoaded();

    public void onAdFailedToLoad(@NonNull AdRequestError adRequestError);

    public void onAdShown();

    public void onAdDismissed();

    public void onLeftApplication();

    public void onReturnedToApplication();
}

SDK 6

The InterstitialAdEventListener interface is divided into two parts: the load callback methods from InterstitialAdLoadListener and rendering methods from InterstitialAdEventListener.

Removed the onLeftApplication() and onReturnedToApplication() methods.

Added the onAdFailedToShow(AdError) method.

interface InterstitialAdLoadListener {
    fun onAdLoaded(interstitialAd: InterstitialAd)

    fun onAdFailedToLoad(adRequestError: AdRequestError)
}

interface InterstitialAdEventListener {
    fun onAdShown()

    fun onAdFailedToShow(adError: AdError)

    fun onAdDismissed()

    fun onAdClicked()

    fun onAdImpression(impressionData: ImpressionData)
}
interface InterstitialAdLoadListener {
    void onAdLoaded(@NonNull InterstitialAd interstitialAd);

    void onAdFailedToLoad(@NonNull AdRequestError adRequestError);
}

interface InterstitialAdEventListener {
    void onAdShown();

    void onAdFailedToShow(@NonNull AdError adError);

    void onAdDismissed();

    void onAdClicked();

    void onAdImpression(@Nullable ImpressionData impressionData);
}

Cleaning the InterstitialAd ad object

SDK 5

Call the onDestroy() method and stop keeping the ad object reference.

SDK 6

The onDestroy() method has been removed.

To clean an ad object, pass null to the function for setting a listener for interstitialAd.setAdEventListener callback methods and stop keeping the ad object reference:

private fun destroyInterstitialAd() {
    interstitialAd?.setAdEventListener(null)
    interstitialAd = null
}
private void destroyInterstitialAd() {
    if (mInterstitialAd != null) {
        mInterstitialAd.setAdEventListener(null);
        mInterstitialAd = null;
    }
}

App open ad

Added a new ad format: app open ad. To learn more, see App open ads.

Yandex mediation

Warning

Make sure to update your used Yandex mediation adapters and adapters for third-party mediation networks to the latest version. Older versions may cause adapter integration errors that can prevent your ads from being served.

New adapter versions

Current versions of Yandex mediation adapters (as of SDK 6.0.1 release):

"com.yandex.ads.mediation:mobileads-adcolony": "4.8.0.6",
"com.yandex.ads.mediation:mobileads-applovin": "11.11.2.0",
"com.yandex.ads.mediation:mobileads-chartboost": "9.3.1.0",
"com.yandex.ads.mediation:mobileads-google": "22.2.0.0",
"com.yandex.ads.mediation:mobileads-inmobi": "10.5.5.0",
"com.yandex.ads.mediation:mobileads-ironsource": "7.4.0.0",
"com.yandex.ads.mediation:mobileads-mintegral": "16.4.71.1",
"com.yandex.ads.mediation:mobileads-mytarget": "5.18.0.0",
"com.yandex.ads.mediation:mobileads-pangle": "5.3.0.4.1",
"com.yandex.ads.mediation:mobileads-startapp": "4.11.0.2",
"com.yandex.ads.mediation:mobileads-tapjoy": "13.1.2.0",
"com.yandex.ads.mediation:mobileads-unityads": "4.8.0.0",
"com.yandex.ads.mediation:mobileads-vungle": "6.12.1.3",

Current versions of adapters for third-party mediation platforms (as of SDK 6.0.1 release):

"com.yandex.ads.adapter:admob-mobileads": "6.0.1.0",
"com.yandex.ads.adapter:ironsource-mobileads": "6.0.1.0"

Renaming the Google AdMob (ex. AdMob) adapter

Renamed the com.yandex.ads.mediation:mobileads-admob artifact as com.yandex.ads.mediation:mobileads-google.

If you use the standardized Yandex mediation build, you don't have to do anything. If you add adapters manually, replace the gradle dependency in your project.

SDK 5

implementation 'com.yandex.ads.mediation:mobileads-admob:<version>'

SDK 6

implementation 'com.yandex.ads.mediation:mobileads-google:<version>'

Here you can find the complete examples for integrations: