将 Google 移动广告 SDK 与 AI 工具集成(Beta 版)

如需优化 AI 辅助输出,请向 AI 环境添加技能。添加技能后,您将为 AI 工具提供与 Google Mobile Ads SDK 相关的特定背景信息,从而改进 AI 辅助代码生成的输出。

本指南介绍了如何针对 Google Mobile Ads SDK 优化 AI 模型。

前提条件

如果您使用 Android Studio,请执行以下操作:

添加技能

Google 提供了一个 SKILL.md 文件,其中包含 AI 工具的说明,可帮助您完成以下集成步骤:

  • Google Mobile Ads SDK 添加到您的项目中。
  • 植入横幅广告。

如需在 AI 工具中使用 Google Mobile Ads SDK 专属技能,请按以下步骤操作:

Android Studio

  1. 在项目的根目录中,创建一个名为 .skills/ 的文件夹。

  2. 为技能创建一个名为 gma-android-integrate 的目录。

  3. gma-android-integrate 目录中,创建一个名为 SKILL.md 的文件。

  4. SKILL.md 文件中,添加以下指令:

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

    如需了解详情,请参阅使用技能扩展智能体模式

在提示中调用技能

将技能添加到项目后,请使用以下示例提示在 AI 工具中调用该技能:

Android Studio

如需调用技能,请输入 @,然后选择 gma-android-integrate 技能。

集成 Google Mobile Ads SDK

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

添加横幅

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

留言反馈

我们会继续评估和优化提供给 AI 代码辅助工具的上下文,以改进其在 Google Mobile Ads SDK 主题上的回答。

如果您对优化 Google Mobile Ads SDK 版 Gemini 有任何反馈,请加入 Google Mobile Ads SDK Discord 频道