### Banner Setup Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/YandexMobileAdsExample/skills/migrate-yandex-ads-sdk-from-7-to-8/SKILL.md In v8, `banner.setAdUnitId(id)` is replaced by passing the ID within the `AdRequest.Builder(id).build()` constructor. Other setup methods remain the same. ```java banner.setAdUnitId(id) banner.setAdSize(size) banner.setBannerAdEventListener(listener) banner.loadAd(AdRequest.Builder().build()) ``` ```java banner.setAdSize(size) banner.setBannerAdEventListener(listener) banner.loadAd(AdRequest.Builder(id).build()) ``` -------------------------------- ### Implement Sticky Banner Ad Source: https://context7.com/yandexmobile/yandex-ads-sdk-android/llms.txt Use `BannerAdView` and `BannerAdSize.sticky()` to create a sticky banner that anchors to the bottom of the screen. Call `BannerAdSize.sticky()` after layout is complete to get accurate dimensions. Remember to destroy the banner ad in `onDestroy()`. ```kotlin class StickyBannerActivity : AppCompatActivity() { private var bannerAd: BannerAdView? = null private var bannerAdSize: BannerAdSize? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_sticky_banner) val container = findViewById(R.id.container) container.viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener { override fun onGlobalLayout() { container.viewTreeObserver.removeOnGlobalLayoutListener(this) val adWidthDp = (container.width / resources.displayMetrics.density).roundToInt() bannerAdSize = BannerAdSize.sticky(this@StickyBannerActivity, adWidthDp) loadBanner() } }) } private fun loadBanner() { val size = bannerAdSize ?: return bannerAd = BannerAdView(this).apply { setAdSize(size) setBannerAdEventListener(object : BannerAdEventListener { override fun onAdLoaded() { Log.d("Ads", "Sticky banner loaded") } override fun onAdFailedToLoad(error: AdRequestError) { Log.e("Ads", "Failed: [${error.code}] ${error.description}") } override fun onAdClicked() { Log.d("Ads", "Clicked") } override fun onImpression(data: ImpressionData?) { Log.d("Ads", "Impression") } }) loadAd(AdRequest.Builder("demo-banner-yandex").build()) } // Add to bottom of layout val params = ConstraintLayout.LayoutParams( size.getWidthInPixels(this), size.getHeightInPixels(this) ).apply { bottomToBottom = ConstraintLayout.LayoutParams.PARENT_ID } findViewById(R.id.container).addView(bannerAd, params) } override fun onDestroy() { bannerAd?.destroy() super.onDestroy() } } ``` -------------------------------- ### Ad Show Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/YandexMobileAdsExample/skills/migrate-yandex-ads-sdk-from-7-to-8/SKILL.md The method for showing interstitial, rewarded, and app open ads remains `ad.show(activity)` in both SDK versions. The event listener setup is also unchanged. ```java ad.setAdEventListener(listener) ad.show(activity) ``` ```java ad.setAdEventListener(listener) ad.show(activity) ``` -------------------------------- ### Standard SDK Initialization Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/ThirdPartyMediationAdapterTemplate/README.md For regular integration, use the standard SDK initialization method provided by the MobileAds class. ```kotlin MobileAds.initialize(context) { onInitializationComplete.invoke() } ``` -------------------------------- ### Initialize SDK Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/YandexMobileAdsExample/skills/migrate-yandex-ads-sdk-from-7-to-8/SKILL.md Use `YandexAds.initialize(...)` for SDK initialization in v8, replacing `MobileAds.initialize(...)` from v7. ```java MobileAds.initialize(...) ``` ```java YandexAds.initialize(...) ``` -------------------------------- ### Initialize Yandex Ads SDK Source: https://context7.com/yandexmobile/yandex-ads-sdk-android/llms.txt Initialize the SDK in `Application.onCreate()` as early as possible. Set privacy flags before initialization. Ads can only be loaded after the initialization callback fires. ```kotlin class MyApplication : MultiDexApplication() { override fun onCreate() { super.onCreate() // Set privacy flags BEFORE initializing YandexAds.setUserConsent(true) // GDPR: user has consented YandexAds.setLocationTracking(false) // Disable location-based targeting YandexAds.setAgeRestricted(false) // COPPA: not a child-directed app YandexAds.enableLogging(true) // Verbose logs for debugging // Preloading for instream ads (optional, call before initialize) YandexInstreamAds.setAdGroupPreloading(true) YandexAds.initialize(this) { // SDK is ready; start loading ads here Log.d("Ads", "SDK initialized, version: ${YandexAds.libraryVersion}") } } } ``` -------------------------------- ### Gradle Build Command for Migration Check Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/YandexMobileAdsExample/skills/migrate-yandex-ads-sdk-from-7-to-8/SKILL.md Execute this command after completing the initial migration steps to identify complex cases that require further attention. The output will be logged to build.log. ```bash ./gradlew compileDebugSources 2>&1 | tee build.log ``` -------------------------------- ### Configure Privacy Policies Source: https://github.com/yandexmobile/yandex-ads-sdk-android/blob/master/ThirdPartyMediationAdapterTemplate/README.md Set user consent and age restrictions before initializing the SDK. Reinitialize if policies change. ```kotlin MobileAds.setAgeRestrictedUser(params.isAgeRestrictedUser()) MobileAds.setLocationConsent(params.hasLocationConsent()) MobileAds.setUserConsent(params.hasUserConsent()) ``` -------------------------------- ### Load and Show Rewarded Ad - Kotlin Source: https://context7.com/yandexmobile/yandex-ads-sdk-android/llms.txt Demonstrates loading and showing a rewarded ad. Ensure `RewardedAdLoadListener` is implemented to handle ad loading callbacks. The `onRewarded` callback delivers reward details upon successful ad completion. ```kotlin class RewardedActivity : AppCompatActivity(), RewardedAdLoadListener { private var rewardedAdLoader: RewardedAdLoader? = null private var rewardedAd: RewardedAd? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_rewarded) rewardedAdLoader = RewardedAdLoader(this) loadAd() findViewById