Build your first Generative AI app in Android Studio

This document outlines how you can use Android Studio to build an application that implements Generative AI using the Google AI SDK. It lays out the process in three steps. Before beginning, ensure that you are running the latest preview version of Android Studio.

Step 1: Build on the New Project template for AI

Start Android Studio and open a new project using File > New Project. Select the new Gemini API starter template.

A New Project template for Gemini API Starter

Figure 1: A New Project template for Gemini API Starter.

Step 2: Generate the API key

In the next step of the wizard, after you choose a project name and location, provide an API key for authentication to the Gemini API. If you don't have a Gemini API key, click the link provided in the wizard to navigate to Google AI Studio and request a new key. Once completed, copy your new API key back into the wizard. Click Finish.

New Project wizard

Figure 2: New Project wizard.

New Project wizard

Figure 3: Copy and paste the API key into the New Project wizard.

Step 3: Start prototyping

Android Studio will automatically set up a project for you with a connection to the Gemini API, simplifying your workflow. Click Run to see the code in action in the Android Emulator. The app comes with a hard-coded prompt asking the model to "Summarize the following text for me"; you can edit or expand the prompt directly in the code to modify what it can do. You can learn more about creating prompts in the Google AI Studio documentation.

Start prototyping with Gemini APIs

Figure 4: Start prototyping with Gemini APIs.

Next steps

Learn more about the Google AI SDK for Android by reviewing the Google AI SDK for Android quick start guide. And for even more code samples, you can import the Generative AI code sample into Android Studio through File > New > Import Sample and searching for Generative AI Sample.

Import Sample Wizard

Figure 5: Import Sample Wizard.

Be sure to try out Gemini's chat, text and multi-modal capabilities in the sample app. Import Sample Wizard

Figure 6: Chat, text and multi-modal capabilities