Intégrer le SDK Google Mobile Ads aux outils d'IA (bêta)

Pour optimiser votre résultat assisté par l'IA, ajoutez une compétence à votre environnement d'IA. En ajoutant une compétence, vous fournissez à votre outil d'IA un contexte spécifique à Google Mobile Ads SDK et améliorez le résultat de la génération de code assistée par l'IA.

Ce guide explique comment optimiser votre modèle d'IA pour Google Mobile Ads SDK.

Prérequis

Si vous utilisez Android Studio, procédez comme suit :

Ajouter une compétence

Google fournit un fichier SKILL.md contenant des instructions pour votre outil d'IA afin de vous aider à suivre les étapes d'intégration suivantes :

  • Ajoutez Google Mobile Ads SDK à votre projet.
  • Implémentez des bannières.

Pour utiliser une compétence spécifique à Google Mobile Ads SDK avec votre outil d'IA, procédez comme suit :

Android Studio

  1. Dans le répertoire racine de votre projet, créez un dossier nommé .skills/.

  2. Créez un répertoire pour votre compétence nommé gma-android-integrate.

  3. Dans le répertoire gma-android-integrate, créez un fichier nommé SKILL.md.

  4. Dans votre fichier SKILL.md, ajoutez les instructions suivantes :

    ---
    name: gma-android-integrate
    description: Provides technical specifications and implementation details for
      the play-services-ads Google Mobile Ads SDK
      (com.google.android.gms:play-services-ads), including Gradle dependencies,
      manifest metadata, initialization patterns, and banner ad configurations. Use
      ONLY for the play-services-ads Google Mobile Ads SDK. Do NOT use for GMA
      Next-Gen SDK (com.google.android.libraries.ads.mobile.sdk:ads-mobile-sdk)
      integrations.
    metadata:
      version: 1.0
    ---
    
    # AI Integration Agent Instructions for the Play Services Google Mobile Ads SDK
    
    ## SDK Integration Workflow
    
    *   **Configure Gradle**:
        -   [ ] Add the latest stable version of
            `com.google.android.gms:play-services-ads` to dependencies.
        -   [ ] Configure `minSdk` (23+) and `compileSdk` (35+).
        -   [ ] Sync Gradle before moving on to the next step.
    *   **Manifest Configuration**:
        -   [ ] Add the following metadata to the `<application>` tag in the
            `AndroidManifest.xml` file:
            ```xml
            <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
            <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-3940256099942544~3347511713"/>
            ```
            **Note**: The sample AdMob App ID
            `ca-app-pub-3940256099942544~3347511713` is for testing purposes only.
            **ALWAYS** remind the user to replace it with their actual AdMob App ID
            before publishing.
    *   **Initialize SDK**:
        -   [ ] Initialize SDK on a background thread.
    
    ### Implementation Details
    
    *   **Version Management**: **ALWAYS** look up and use the latest stable
        version. Do not assume a version number.
    *   **Initialization**: **ALWAYS** call `MobileAds.initialize()` on a background
        thread.
    
    ## Banner Ads
    
    Banner ads are rectangular image or text ads that occupy a spot within an app's
    layout. They remain on screen during user interaction and can refresh
    automatically.
    
    ### Strategic Recommendations
    
    *   **Confirm Ad Type**: If the user asks for a "banner ad" without specifying a
        type, confirm the desired type.
    *   **Suggest Large Anchored Adaptive**: Suggest large anchored adaptive banners
        over "fixed size". Explain they are designed to increase engagement and
        revenue potential. If told that large adaptive is too large, suggest
        standard anchored adaptive over fixed size ads.
    *   **Type Clarifications**:
        *   **Anchored Adaptive**: Ask if it should be anchored to the **top** or
            **bottom**.
        *   **Inline Adaptive**: Use this type for ads placed inside scrollable
            content (e.g., `RecyclerView` or `ScrollView`). **Validate** the ad
            container is scrollable before implementing; if not scrollable, default
            to **Large Anchored Adaptive**.
    
    ### Implementation Checklist
    
    -   [ ] Create UI container for `AdView`.
    -   [ ] Initialize `AdView` with ad unit ID and ad size.
    -   [ ] Call `adView.loadAd()`.
    -   [ ] **Mandatory**: Add `adView.destroy()` to the appropriate lifecycle
        cleanup (e.g., `onDestroy`).

    Pour en savoir plus, consultez Étendre le mode Agent avec des compétences.

Appeler la compétence dans votre invite

Une fois la compétence ajoutée à votre projet, utilisez les exemples d'invites suivants pour l'appeler dans votre outil d'IA :

Android Studio

Pour appeler la compétence, saisissez @ et sélectionnez la compétence gma-android-integrate.

Intégrer Google Mobile Ads SDK

@gma-android-integrate Integrate the latest version of Google Mobile Ads SDK to my project.

Ajouter une bannière

@gma-android-integrate Add an anchored adaptive banner ad to the bottom of the screen.

Laisser un commentaire

Nous continuons d'évaluer et d'optimiser le contexte fourni aux outils d'assistance au code basés sur l'IA afin d'améliorer leurs réponses sur les sujets liés aux Google Mobile Ads SDK.

Si vous avez des commentaires sur l'optimisation de Gemini pour Google Mobile Ads SDK, rejoignez le Google Mobile Ads SDK canal Discord.