Guide to migrating to version 6

Warning

Be sure to update to the latest adapter versions (Yandex Mediation and adapters for third-party mediation networks). Otherwise, errors from improper adapter integration might occur, preventing the ad 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 your ad type:

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

An adaptive sticky banner is a small, automatically updated ad placed at the bottom or top of the app screen.

The banner doesn't overlap the main app content and is often used in gaming apps.

The height of the sticky banner is determined automatically, adapting to the device screen size and not exceeding 15% of the screen height.

Warning

Starting with version 6.0.0, adaptive sticky banners can refresh automatically.

If you previously implemented auto-refresh for a sticky-banner, you should now disable it.

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

An adaptive inline banner is a flexible banner ad format that ensures maximum efficiency by optimizing ad size for each device.

The banner height is selected automatically and can reach the height of the device screen.

Typically, this format is used in feed-based apps or contexts where it's acceptable to primarily focus user attention on ads.

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

The approach to creating and loading advertisements has been revised. 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.

Loading ads

SDK 5

One object is now used both for loading and serving ads:

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 is used 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 show
        }

        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 show
    }

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

Ad serving

SDK 5

Check if the ad is loaded before displaying it.

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

SDK 6

You don't need to check whether the ad has been 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 ads

The approach to creating and loading advertisements has been revised. 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.

Loading ads

SDK 5

One object is now used both for loading and serving ads:

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 loader object 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 show
        }

        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 serving

SDK 5

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

SDK 6

You don't need to check whether the ad has been 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 ad loading and rendering.

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 ads

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

Yandex Mediation

Warning

Be sure to update to the latest adapter versions (Yandex Mediation and adapters for third-party mediation networks). Otherwise, errors from improper adapter integration might occur, preventing the ad 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 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: