Integration Mobile Ads SDK
System: Yandex Advertising Network, Adfox
Integrating the Yandex Mobile Ads SDK into your app is the first step toward serving ads and generating revenue. After integrating the SDK, you can choose an ad format for your app monetization (for example, banner ads or rewarded ads) and perform its setup.
Prerequisites
To prepare your app, follow the steps described in the next sections.
App requirements
- Use Android Studio 2021 or higher.
- Use Android Gradle Plugin version 8.7.0 or higher.
- Check that your app's build file uses the following values:
- minSdkVersion 21 or higher.
- compileSdkVersion 34 or higher.
- If you use the AppMetrica SDK in your app, make sure that you have version 7.2.1 or higher (within major version 7) installed.
Setting up the app in your Yandex Advertising Network account
Here's how to register your app in the Yandex Advertising Network:
- Log in or register your account in the Yandex Advertising Network.
- Register your app in the Yandex Advertising Network.
Set up your app
-
Add support for the Google and Maven Central repositories to the project configuration.
Depending on the build settings, these repositories can be added either to the project's build.gradle file or to the repositories block in settings.gradle as shown below:
build.gradlesettings.gradle// Project-level build.gradle file buildscript { repositories { google() mavenCentral() } } allprojects { repositories { google() mavenCentral() } }// Project-level settings.gradle file pluginManagement { repositories { google() mavenCentral() gradlePluginPortal() } } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() mavenCentral() } } -
Add a dependency on the Yandex Mobile Ads SDK to the Gradle file at your app's module level, usually app/build.gradle:
dependencies { implementation 'com.yandex.android:mobileads:7.18.5' } -
Set up permission to use an advertising ID (for apps using SDK versions older than 4.5.0).
How to 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 for the user.
If your app runs a Yandex Mobile Ads SDK version below 4.5, add com.google.android.gms.permission.AD_ID to the AndroidManifest.xml file:
<manifest> <application> <!-- For apps targeting Android 13 or higher & Yandex Mobile Ads SDK versions lower than 4.5.0 --> <uses-permission android:name="com.google.android.gms.permission.AD_ID"/> </application> </manifest>As of version 4.5.0, the Yandex Mobile Ads SDK adds com.google.android.gms.permission.AD_ID by default. 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 more 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 keep the permission from being added to the application's main manifest, add the following code to AndroidManifest.xml:
<manifest> <application> <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/> </application> </manifest>Warning
Lack of permission and access to the ID may impact your revenue, because your app may serve less relevant ads.
Initialize the Yandex Mobile Ads SDK
Successfully initializing the Yandex Mobile Ads SDK is a prerequisite for correctly integrating the library. By default, the SDK is initialized automatically on app startup. This speeds up ad loading and thus increases your monetization revenue.
If you need to set up privacy policies for personal data in your app, make sure to do this before initializing the Yandex Mobile Ads SDK.
You can set up these policies using the AndroidManifest.file or right before initializing the SDK manually.
COPPA setup
If you've chosen automatic initialization, add the following code to the AndroidManifest.xml file to notify the Yandex Mobile Ads SDK when the app user is a child:
<manifest>
<application>
<!-- Disable the use of child's personal data for app monetization. -->
<meta-data
android:name="@string/yandex_mobileads_age_restricted_user"
android:value="true" />
</application>
</manifest>
Manual SDK initialization
If necessary, you can disable auto initialization and initialize the library manually by using the initialize() method:
<manifest>
<application>
<!-- Disable automatic sdk initialization. -->
<meta-data
android:name="com.yandex.mobile.ads.AUTOMATIC_SDK_INITIALIZATION"
android:value="false" />
</application>
</manifest>
Warning
Even if you have automatic initialization disabled, the SDK initializes before the first ad request if you haven't already called MobileAds.initialize() manually. For more information about initialization logs, read Testing SDK integration below.
We recommend adding the initialization code to the onCreate method of the Application class. Make sure to set up the privacy policies for personal data before you initialize the SDK:
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
// Configure the user data privacy policy before sdk init
MobileAds.initialize(this) {
// Now you can use ads
}
}
}
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
// Configure the user data privacy policy before sdk init
MobileAds.initialize(this, () -> {
// Now you can use ads
});
}
}
Testing SDK integration
You can verify the success of the library integration using the SDK's built-in integration testing tool.
To do so, after adding the dependency and initializing the SDK, rebuild the project.
Open Logcat and search for the “Yandex Ads” keyword.
The command outputs the integration status logs. You'll see a message indicating whether the integration was successful. If there's a problem, you'll see a detailed description along with steps to resolve it. Sample command output:
mobileads$ adb logcat | grep 'Yandex Ads' -i
[Yandex Ads] I Yandex Mobile Ads 7.18.5 integrated successfully
[Yandex Ads] I Yandex Mobile Ads 7.18.5 initialized successfully
The log shows two separate events:
integrated successfully: Integration check (SDK hasn't been initialized yet).initialized successfully: Successful SDK initialization.
Indicator of an outdated library version
Note
The indicator is available in debug mode.
If the version of the Yandex Mobile Ads SDK is outdated, an indicator in the form of a toast message will be displayed on library initialization or when loading an ad.
Issue details are also logged to the app logs.
Sample logs:
***************************************************************************************
* The integrated version of the Yandex Mobile Ads SDK is outdated. *
* Please update com.yandex.android:mobileads to the latest version. *
* Learn more about the latest version of the SDK here: *
* https://yandex.com/dev/mobile-ads/doc/android/quick-start/android-ads-component.html *
* Changelog: https://yandex.com/dev/mobile-ads/doc/intro/changelog-android.html *
***************************************************************************************
To disable the indicator, call the enableDebugErrorIndicator method set to false:
MobileAds.enableDebugErrorIndicator(false)
Tip
We don't recommend disabling validation for the outdated SDK version indicator. Make sure to use the latest library version to maximize your ad revenue.
Lint check for the latest SDK version
When building the app's release version, a lint check will be run to verify that you're using the latest SDK version.
Lint checks are triggered by a call to the lintVitalRelease gradle task, which crashes if the advertising SDK version is outdated.
The check won't let the app build if there's a newer SDK version available.
To disable checking for the the latest SDK version, use the standard way of preventing lint checks through gradle code (for more information, see the Android documentation).
android {
lintOptions {
disable 'MobileAdsSdkOutdatedVersion'
}
}
Next steps
Once you've successfully integrated the Yandex Mobile Ads SDK, you can proceed to implementing your ad formats.
Select one of the following types of ads that best suits your app:
|
Ad format |
Yandex Advertising Network |
Adfox |
Description |
|
|
|
Adaptive inline banners are a flexible format of banner advertising, providing maximum efficiency by optimizing the size of the ad on 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. |
|
|
|
|
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 the sticky banner is determined automatically, adapting to the device screen size and not exceeding 15% of the screen height. |
|
|
|
|
Interstitial advertising is a full-screen ad format embedded within the app content during natural pauses, such as transitioning between game levels or completing a target action. When users see interstitial ads, their attention is entirely focused on the ads, which results in a higher cost for such impressions. Overuse of this format can worsen user interaction. |
|
|
|
|
Rewarded ads are a popular full-screen ad format, where the user receives a reward for viewing the ad. The display of this ad type is activated by the user, for instance, to receive a bonus or additional life in a game. High user motivation makes this ad format the most popular and profitable in free apps. |
|
|
|
|
Native advertising is an ad type where the layout can be defined on the app side. This feature allows you to change the visual style of ads and their placement, considering the app design specifics. Ad rendering is performed with native platform tools, which enhances ad performance and quality. You can set the layout of your native ads using a template or manually. If you choose to use a template, the ad layout will be set on the SDK side. |
|
|
|
|
App open ads are a special ad format for monetizing your app load screens. These ads can be closed at any time and are designed to be served when users bring your app to the foreground, either at launch or when returning to it from the background. |
|
|
|
|
Ad feeds are units that consist of a sequence of ads. Feeds can be added to your app as its main content, or they may come after the existing content. Feeds may contain dozens of ads, which are loaded sequentially (several ads are loaded at once). |
|
|
|
|
InStream is an ad format that lets you monetize your app by serving ads while video content is playing. An InStream ad consists of a scenario with multiple video blocks. The type of video unit in an InStream scenario determines how the video ad should be played relative to the main video content. |

