Integrare l'SDK Google Mobile Ads con gli strumenti di AI (beta)

Per ottimizzare l'output assistito dall'AI, aggiungi una competenza al tuo ambiente AI. Aggiungendo una competenza, fornisci al tuo strumento AI un contesto specifico per Google Mobile Ads SDK e migliori l'output della generazione di codice assistita dall'AI.

Questa guida illustra come ottimizzare il modello AI per Google Mobile Ads SDK.

Prerequisiti

Se utilizzi Android Studio:

Aggiungere una competenza

Google fornisce un file SKILL.md con le istruzioni per lo strumento AI per aiutarti a eseguire i seguenti passaggi di integrazione:

  • Aggiungi Google Mobile Ads SDK al tuo progetto.
  • Implementa gli annunci banner.

Per utilizzare una competenza specifica per Google Mobile Ads SDK con lo strumento AI:

Android Studio

  1. Nella directory root del progetto, crea una cartella denominata .skills/.

  2. Crea una directory per la competenza denominata gma-android-integrate.

  3. Nella directory gma-android-integrate, crea un file denominato SKILL.md.

  4. Nel file SKILL.md, aggiungi le seguenti istruzioni:

    ---
    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`).

    Per maggiori dettagli, vedi Estendere la modalità agente con le competenze.

Richiamare la competenza nel prompt

Dopo aver aggiunto la competenza al progetto, utilizza i seguenti prompt di esempio per richiamarla nello strumento AI:

Android Studio

Per richiamare la competenza, digita @ e seleziona la competenza gma-android-integrate.

Integrare Google Mobile Ads SDK

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

Aggiungere un banner

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

Lasciare un feedback

Continuiamo a valutare e ottimizzare il contesto fornito agli strumenti di assistenza al codice AI per migliorare le loro risposte sugli argomenti Google Mobile Ads SDK.

Se hai feedback sull'ottimizzazione di Gemini per Google Mobile Ads SDK, unisciti al Google Mobile Ads SDK canale Discord.