Integrating the Mobile Ads SDK
This is an archived version of the documentation. Actual documentation for all platforms can be found here.
- To load ads of any type, Android 4.1 or later is required.
- Video ads are only selected for devices with Android 5.0 or later.
Several integration methods are supported:
You can enable all available adapters automatically using the YandexMobileAdsMediation shared mediation library.
Add the YandexMobileAdsMediation dependency to the build.gradle file in your app's module:
dependencies { ... implementation 'com.yandex.android:mobileads-mediation:5.10.0.0' }
For each adapter, the latest compatible version is selected automatically.
Update the dependency on Koltin Gradle Plugin to the build.gradle file in your app's module:
dependencies { ... classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10") }
Add Java 8 support to the build.gradle root file in your project:
android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } }
Add the following code to the build.gradle file in your app's module:
// IronSource maven { url 'https://android-sdk.is.com/' } // Pangle maven { url 'https://artifact.bytedance.com/repository/pangle' } // Tapjoy maven { url "https://sdk.tapjoy.com/" } // Mintegral maven { url "https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea" }
Set up permission to use the ad ID.
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"/>
If you don't need to enable all the available adapters automatically, add the YandexMobileAdsMediation dependency to the build.gradle file in your app's module:
dependencies { ... implementation 'com.yandex.android:mobileads:5.10.0' }
To enable relevant adapters, follow their instructions.
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 } }
Set up permission to use the ad ID.
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.
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.