AI code completion

Gemini offers AI-enabled autocompletion of code in Android Studio that appears as gray italicized text as you type. We call this feature AI code completion. This feature saves you time and lets you complete coding projects faster by suggesting full functions. When AI code completion is enabled, Gemini might send additional information from your codebase such as surrounding pieces of your code, file types, and other necessary information to provide context to the LLM and provide more relevant suggestions.

Get started

To get started with AI code completion, follow these steps:

  1. Download the latest version of Android Studio Jellyfish or higher.
  2. To launch Gemini, open or start an Android Studio project and click View > Tool Windows > Gemini.
  3. Sign in to your Google Account.
  4. AI code completion only works when Gemini can access context from your codebase. Enable this during Gemini sign-in or any time through Android Studio > Settings > Gemini > Augment responses with information from your codebase.
  5. Open a file and start typing. Suggestions only trigger when the cursor is at the end of a line or anywhere on a blank line.
  6. Press Tab to accept a suggestion and Esc to clear a suggestion.

FAQ

How do I get access to AI code completion?

This functionality only works when Gemini can access context from your codebase. Enable this through Android Studio > Settings > Gemini > Augment responses with information from your codebase. AI-enabled autocompletion appears as you type. You can also use natural language comments to trigger code completions by adding comments.

Why am I not able to see a code completion?

First, check that you're logged in to Gemini and have opted in to AI code completion at Android Studio > Settings > Gemini. Keep in mind that the system won't always generate code completions. It's possible that the model doesn't have enough information to generate a response with high confidence.

How can I turn off AI code completion in Android Studio?

To disable AI code completion, go to Android Studio > Settings > Gemini and revoke consent and turn off AI code completion.