追加するテンプレートを選択すると、対応するウィザード ウィンドウが表示され、名前などコンポーネントの設定情報の入力を求められます。設定情報を入力すると、Android Studio で新しいコンポーネントのファイルが作成され、開きます。さらに、Gradle ビルドが実行され、プロジェクトが同期されます。
Gemini API テンプレートを使用して、Google AI SDK を使用して生成 AI を実装するアプリケーションを構築します。
ステップ 1: AI の [New Project] テンプレートを基に構築する
Android Studio を起動し、[File] > [New Project] を使用して新しいプロジェクトを開きます。[Gemini API Starter] テンプレートを選択します。
[新しいプロジェクト] 画面で Gemini API テンプレートを選択します。
ステップ 2: API キーを生成する
ウィザードの次のステップで、プロジェクト名とロケーションを選択したら、Gemini API への認証用の API キーを指定します。Gemini API キーがない場合は、ウィザードに表示されるリンクをクリックして Google AI Studio に移動し、新しいキーをリクエストします。完了したら、新しい API キーをウィザードにコピーして戻します。[完了] をクリックします。
Gemini API テンプレートの新しいプロジェクト ウィザード。API キーをコピーして、新しいプロジェクト ウィザードに貼り付けます。
ステップ 3: プロトタイピングを開始する
Android Studio は、Gemini API への接続を使用してプロジェクトを自動的にセットアップし、ワークフローを簡素化します。[実行] をクリックすると、Android Emulator でコードが実行されます。このアプリには、モデルに「次のテキストを要約して」と尋ねるプロンプトがハードコードされています。コード内でプロンプトを直接編集または拡張して、モデルの機能を変更できます。プロンプトの作成について詳しくは、Google AI Studio のドキュメントをご覧ください。
Gemini API を使用してプロトタイピングを開始します。
詳細
Google AI SDK for Android について詳しくは、Google AI SDK for Android のクイック スタートガイドをご覧ください。さらに多くのコードサンプルについては、[File] > [New] > [Import Sample] を選択し、[Generative AI Sample] を検索して、Generative AI コードサンプルを Android Studio にインポートできます。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["必要な情報がない","missingTheInformationINeed","thumb-down"],["複雑すぎる / 手順が多すぎる","tooComplicatedTooManySteps","thumb-down"],["最新ではない","outOfDate","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["サンプル / コードに問題がある","samplesCodeIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-08-10 UTC。"],[],[],null,["# Add code from a template\n\nAndroid Studio provides code templates that follow the Android design and\ndevelopment best practices to get you on the right track to creating\nbeautiful, functional apps. You can use templates to create new app modules,\nindividual activities, or other specific Android project components.\n\nSome templates provide starter code for common usage contexts, such as\nnavigation drawers or login screens. You can choose from these app module\nand activity templates when you first [create your project](/studio/projects/create-project),\nwhen you [add a new app module within an existing project](/studio/projects/add-app-module),\nor when you add a new activity within an app module.\n\nIn addition to activities, you can also add other Android project components\nto an existing app using templates. These templates include both code\ncomponents, such as services and fragments, and non-code components, such as\nfolders and XML files.\n\nThis page discusses how to add Android project components like activities to\nyour project and describes the commonly used activity templates available in\nAndroid Studio. Note that most templates depend on the [Android Support\nLibrary](/tools/support-library/features) to include user interface principles based on [Material Design](/design/material).\n\nAdd a project component\n-----------------------\n\n**Figure 1** . The templates menu, accessible through the\n**File** \\\u003e **New** menu or by right-clicking in the\n**Project** window.\n\nAndroid Studio groups templates by the type of component that they add, such\nas an **Activity** or an **XML** file, as shown in figure 1.\n\nTo add an Android project component using a template, use the **Project**\nwindow. Right-click on the\nfolder in which you want to add the new component, and select **New**. Based\non what components can be added to the folder you clicked on, you then see a\nlist of template types like those shown in figure 1.\n\nWhen you select the template you want to add, a corresponding wizard window\nappears and asks for the component's configuration information, such as its\nname. After you enter the configuration information, Android Studio creates\nand opens the files for your new component. It also runs a Gradle build to\nsync your project.\n\nSelect an activity template\n---------------------------\n\n**Figure 2**. The Empty Compose Activity template.\n\nOne of the most common uses of templates is adding new activities to an\nexisting app module. There are templates for creating screens for logging\ninto an account, presenting a list of items with details, or scrolling\nthrough a long block of text.\n\nAndroid Studio also provides templates for a variety of different app module\ntypes, including Wear OS, Android TV, and Cloud App Engine. You can view\ntemplates for these different module types when [adding a project component](#FindTemplates).\nTemplates also exist for more API-specific modules and activities, such as\nGoogle AdMobs Ads and Google Maps.\n\nOne of the most commonly used templates is the Empty Compose Activity\ntemplate, which creates an empty activity with a sample composable and a\npreview of the composable. It lets you to start from scratch when building\nyour app module or activity.\n\nUse the Gemini API template\n---------------------------\n\n| **Note:** The Gemini API template has been temporarily removed starting in Android Studio Narwhal \\| 2025.1.1. To use the template, download a previous version of Android Studio, which still supports the template, from the [Android Studio\n| download archive](/studio/archive) as a temporary workaround.\n\nUse the Gemini API template to build an application that implements\nGenerative AI using the [Google AI SDK](http://ai.google.dev/tutorials/android_quickstart?utm_source=android&utm_medium=referral).\n\n### Step 1: Build on the New Project template for AI\n\nStart Android Studio and open a new project using **File \\\u003e New Project** .\nSelect the **Gemini API Starter** template.\nChoose the Gemini API template on the **New Project** screen.\n\n### Step 2: Generate the API key\n\nIn the next step of the wizard, after you choose a project name and location,\nprovide an API key for authentication to the Gemini API. If you don't have a\nGemini API key, click the link provided in the wizard to navigate to\n[Google AI Studio](https://makersuite.google.com/app/apikey) and request a\nnew key. Once completed, copy your new API key back into the wizard. Click\n**Finish**.\nNew Project wizard for the Gemini API template. Copy and paste the API key into the New Project wizard.\n\n### Step 3: Start prototyping\n\nAndroid Studio automatically sets up a project for you with a connection to\nthe Gemini API, simplifying your workflow. Click **Run** to see the code in\naction in the Android Emulator. The app comes with a hard-coded prompt\nasking the model to \"Summarize the following text for me\"; you can edit or\nexpand the prompt directly in the code to modify what it can do. You can\nlearn more about creating prompts in the [Google AI Studio documentation](https://ai.google.dev/gemini-api/docs/ai-studio-quickstart).\nStart prototyping with Gemini APIs. **Important:** Remember, your API key is a secret! Don't share it with anyone, and it is strongly recommended that you don't check in an API key into your version control. The Gemini API Starter template stores the API key in a `local.properties` file (which is located in your project's root directory, but excluded from version control) and uses the [Secrets Gradle plugin](https://github.com/google/secrets-gradle-plugin) for Android to read the API key as a build configuration variable.\n\n### Learn more\n\nLearn more about the Google AI SDK for Android by reviewing the Google AI SDK\nfor Android [quick start guide](http://ai.google.dev/tutorials/android_quickstart?utm_source=android&utm_medium=referral).\nAnd for even more code samples, you can import the Generative AI code sample\ninto Android Studio through **File \\\u003e New \\\u003e Import Sample** and searching for\n**Generative AI Sample**.\nImport Generative AI Sample Wizard.\n\nTry out Gemini's chat, text, and multi-modal capabilities in the sample app.\n\n\u003cbr /\u003e\n\nGemini's chat, text and multi-modal capabilities. c\n\n\u003cbr /\u003e"]]