All skills
google avatar

/google-mobile-ads-banner

@329fa26
by googlegoogle/skills21k stars
1,698

Provides instructions to implement, integrate, or configure Google Mobile Ads (GMA) banner ads in Android, iOS, or Unity mobile applications. Use when the task involves setting up banner ads in a mobile application. Don't use for other ad formats like interstitial or rewarded ads.

Use this Skill: https://skilld.dev/gh/google/skills/google-mobile-ads-banner

This session only. Nothing lands on disk.

referencesandroid-banner.md

≈760 tokens on demand. Your agent reads this file only when SKILL.md points to it.

AI Integration Agent Instructions for Android Banner Ads

Required Imports

Use the following imports to implement a banner ad:

import com.google.android.libraries.ads.mobile.sdk.banner.AdSize
import com.google.android.libraries.ads.mobile.sdk.banner.AdView
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAd
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRequest
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback
import com.google.android.libraries.ads.mobile.sdk.common.LoadAdError

Method Signatures

Use the following method signatures to implement banner ads:

The BannerAdRequest object takes the ad unit ID and AdSize:

BannerAdRequest.Builder(adUnitId: String, adSize: AdSize).build()

The method signature to load a banner ad from AdView:

fun loadAd(
    adRequest: BannerAdRequest,
    adLoadCallback: AdLoadCallback<BannerAd>
): Unit

The AdLoadCallback interface is defined as:

interface AdLoadCallback<T> {
    fun onAdLoaded(ad: T): Unit
    fun onAdFailedToLoad(adError: LoadAdError): Unit
}

Gotchas

UI Threading: MANDATORY: Callbacks in GMA-Next Gen SDK are invoked on a background thread. ALL UI-RELATED OPERATIONS (e.g., Toasts, View updates, Fragment transactions) MUST be wrapped in runOnUiThread {} or Dispatchers.Main.launch {} within GMA SDK callbacks. SKIPPING THIS STEP WILL CAUSE THE APPLICATION TO CRASH.

Banner Ad workflow

  1. Define the ad view

    • Use AdView for defining GMA Next-Gen SDK banners instead of the deprecated BannerAd.
  2. Set the ad size:

    • Set the width you use for AdSize to 360 for testing purposes. Mention using the device width is also a common approach.
    • Use the appropriate AdSize method and test ad unit ID (ca-app-pub-3940256099942544/9214589741) based on the ad type:
      • For a large anchored adaptive banner: Use AdSize.getLargeAnchoredAdaptiveBannerAdSize(context, width).
        • If given feedback that large anchored adaptive banners are too tall, use AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(context, width).
      • For an inline adaptive banner: Use AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(context, width).
    • Pass the AdSize and ad unit ID to the BannerAdRequest.Builder, not directly on the AdView.
  3. Register for ad load events:

    • Pass the AdLoadCallback implementation in the loadAd() method, not directly on the AdView.
  4. Load the banner ad:

  5. Verify the implementation: Check the build to ensure there are no compile errors:

    • Run gradle build -x test to confirm a successful clean build. Resolve any GMA SDK related compile errors.

Links

Additional documentation:

Source: SKILL.md on GitHub

No alerts8d3 checks · Risk SAFE
  • Gen Agent Trust Hub8d

    This skill provides instructions for implementing Google Mobile Ads banner ads across various platforms. It includes standard developer workflows, such as using local build tools to verify code integrity, and references official documentation.

  • Socket8d

    No alerts

  • Snyk8d

    Risk: LOW · No issues

Signed by skilld at 329fa26. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated last week
metadata
{
  "version": "1.1.0",
  "category": "GoogleAds"
}

README badge

README badge for google/skills/google-mobile-ads-banner