Integrowanie pakietu SDK do reklam mobilnych Google z narzędziami AI (beta)

Aby zoptymalizować Gemini w Android Studio, użyj w projekcie pliku AGENTS.md. Dodając do projektu AGENTS.md, dostarczasz Gemini kontekst specyficzny dla Google Mobile Ads SDK i ulepszasz wyniki generowania kodu z pomocą AI. Więcej informacji znajdziesz w artykule Dostosowywanie Gemini za pomocą AGENTS.md plików.

Ten przewodnik zawiera informacje o optymalizacji Gemini w Android Studio pod kątem Google Mobile Ads SDK.

Zanim zaczniesz

Zanim przejdziesz dalej:

Dodawanie pliku AGENTS.md do projektu

Google udostępnia AGENTS.md plik z instrukcjami dla Gemini, który pomoże Ci w wykonaniu tych kroków integracji:

  • Dodaj Google Mobile Ads SDK do projektu.
  • Wdróż banery reklamowe.

Aby używać instrukcji dotyczących Google Mobile Ads SDK w funkcji pomocy w pisaniu kodu opartej na AI, wykonaj te czynności:

  1. Utwórz nowy plik o nazwie AGENTS.md w dowolnym miejscu w systemie plików projektu.

  2. W pliku AGENTS.md dodaj te instrukcje:

# AI Integration Agent Instructions for the Google Mobile Ads SDK

## Integrate the SDK

*   When I ask to integrate the Google Mobile Ads SDK, **always** use the latest
    stable version for `com.google.android.gms:play-services-ads`.
*   After looking up the latest stable version of
    `com.google.android.gms:play-services-ads`, **always** check the project for
    a version catalog to manage dependencies.
*   Make sure the project meets the SDK requirements of `minSdk` 23 or higher
    and `compileSdk` of 35 or higher.
*   **Always** make sure there is a `<metadata>` tag for application ID in the
    project. If it's not there, add it.
*   You MUST initialize the Google Mobile Ads SDK on a background thread, as
    recommended in the Google Mobile Ads SDK v24.0.0 release notes.

## Banner Ads

*   When I ask to implement a banner ad or something similar, without specifying
    a type, **always** follow up to confirm the type of ad.
*   When I ask for an "anchored adaptive" ad, ask me if I want the ad anchored
    to the top or bottom of the screen.
*   When I ask for an "inline" adaptive banner ad, explain that inline adaptive
    ads are used for scrolling content. If my application has no scrollable view
    elements (e.g. `ScrollView` or `List`), default to implement an anchored
    adaptive banner ad.
*   When I ask for a "collapsible" banner ad, create an extra parameter that
    aligns the expanded ad to the `AdView`. Ask me if I want the ad collapsed to
    the top or bottom.
*   When I ask for a "fixed size" banner ad, **always** ask me if I'm sure or
    would I like to implement an anchored adaptive banner ad. Explain why
    anchored adaptive banner ads perform better than fixed size ads.

*   **Mandatory `AdView` Implementation Steps:**
    *   **Always** provide the code for a UI container intended to host the
        `AdView`.
    *   **Always** call `adView.destroy()` to prevent memory leaks.

Promptowanie Gemini w trybie agenta

Po skonfigurowaniu pliku AGENTS.md możesz poprosić Gemini w Android Studio o pomoc w trybie agenta.

W trybie agenta możesz używać tych przykładowych promptów:

Integracja pakietu SDK

Integrate the latest version of the GMA SDK to my project. Refer to the Android
documentation.

Dodaj baner

Add an anchored adaptive banner ad to the bottom of the screen. Refer to the
Android documentation.

Wyślij opinię

Stale oceniamy i optymalizujemy kontekst przekazywany do narzędzi AI do pomocy w pisaniu kodu, aby poprawić ich odpowiedzi na tematy Google Mobile Ads SDK.

Jeśli masz uwagi dotyczące optymalizacji Gemini pod kątem Google Mobile Ads SDK, dołącz do Google Mobile Ads SDK kanału na Discordzie.