Integrating the Mobile Ads SDK

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

  1. Initializing the Mobile Ads SDK
Note.
  1. To load ads of any type, Android 4.1 or later is required.
  2. Video ads are only selected for devices with Android 5.0 or later.

The Yandex Mobile Ads library is provided in AAR format. To enable the Mobile Ads SDK:

  1. Add the dependency on Yandex Mobile Ads to the build.gradle file in your app's module:

    dependencies {
        ...
        implementation 'com.yandex.android:mobileads:5.10.0'
    }
  2. Update the dependency on Koltin Gradle Plugin to the build.gradle root file in your project:

    dependencies {
        ...
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10")
    }
  3. Add Java 8 support to the build.gradle file in your app's module:

    android {
    
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
  4. Set up permission to use the ad ID.

    The ad ID is a unique identifier provided by Google Play services for displaying ads to users who opt in to personalized ads. Users can opt out of ad personalization or reset their ID in the settings. In this case, advertising networks won't be able to use the ID to select relevant ads.

    A new permission has been made available in the Yandex Mobile Ads SDK version 4.5.0 and higher: com.google.android.gms.permission.AD_ID. It's written in the library's AndroidManifest.xml file. Because of this, you don't have to specify it in the application's main manifest. The permission allows you to use an ad ID to select relevant ads from advertising networks.

    You can delete the permission if necessary. For example, if a policy does not allow the use of an ID for ad selection, such as the Families Policy.

    To prevent the permission from being added to the application's main manifest, add the following line to AndroidManifest.xml:

    <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

Initializing the Mobile Ads SDK

Before loading ads, initialize the library using the initialize() method. Initialization makes ads load faster.

Note.

It's needed each time the app starts. That's why we recommend that you add the initialization code to the onCreate method of the Application class.

Initialization example:
public class YandexApplication extends Application {

    private static final String YANDEX_MOBILE_ADS_TAG = "YandexMobileAds";

    @Override
    public void onCreate() {
        super.onCreate();

        MobileAds.initialize(this, new InitializationListener() {
            @Override
            public void onInitializationCompleted() {
                Log.d(YANDEX_MOBILE_ADS_TAG, "SDK initialized");
            }
        });
    }
}

See the SDK usage examples.