Gemini in Android Studio

Gemini in Android Studio is your coding companion for Android development. It's powered by artificial intelligence and can understand natural language. It helps you be more productive by answering your Android development queries. Gemini can help Android developers generate code, find relevant resources, learn best practices, and save time.

Gemini is still an early experiment, and might sometimes provide inaccurate, misleading or false information while presenting it confidently. Gemini might give you working code that doesn't produce the expected output, or provide you with code that is not optimal or incomplete. Always double-check Gemini's responses and carefully test and review code for errors, bugs, and vulnerabilities before relying on it. Gemini's new capabilities can help you by offering new ways to write code, create test cases, or update APIs.

Get started

Here's how to set up Gemini:

  1. Download the latest version of Android Studio Jellyfish or higher.
  2. Recommended: Agree to send data to Google so we can better understand how effective Gemini is. Give permission to share data either when you first install Android Studio or later at File > Settings > Appearance & Behavior > System Settings > Data Sharing (Android Studio > Settings > Appearance & Behavior > System Settings > Data Sharing on macOS).
  3. To launch Gemini, open or start an Android Studio project and click View > Tool Windows > Gemini.
  4. Sign in to your Google account when asked, if you aren't already signed in. The chat box appears and you can start using Gemini's interactive, conversational interface.

Get answers from Gemini

The main interface for interacting with Gemini is the chat window. You can use it to ask questions ranging from very simple and open-ended ones to specific problems that you need help with. Here are some examples of things you might ask; however, feel free to experiment with any topics related to Android development:

  • How do I add camera support to my app?
  • I want to create a Room database.
  • Can you remind me of the format for javadocs?
  • What is dark theme?
  • What's the best way to get location on Android?

Gemini remembers the context of the conversation, so you can also ask it follow-up questions, such as:

  • Can you give me the code for this in Kotlin?
  • Can you show me how to do it in Compose?

You can also ask Gemini about Android Studio itself, for example:

  • How do I analyze jank in my app?
  • Where do I find the CPU profiler?

Tips for engaging with Gemini

Gemini's answers differ based on how you ask your question. Here are some tips on how to optimize the answers from Gemini:

  • Be specific. If there are certain libraries, APIs, or approaches that you'd like to use, include them in your question.
    How do I add camera support to my app using CameraX?
    How do I add camera support to my app?
  • Describe the structure of the desired answer. If you want to insert code generated by Gemini into your app and need it in a certain format, give it those instructions.
    Insert comments into this code. Use double slashes for the comments, and put each comment above the line of code it describes.
    Write code comments for this code.
  • Break up complex requests into a series of simpler questions. Especially when you're asking for code, asking a series of simpler questions yields a more comprehensive answer overall.
    1. Give me the MainActivity.kt file for an app with a login screen.
    2. Can you add a class that represents a user profile?
    3. Can you add code that supports multiple user profiles?
    How do I create an app with a login screen that supports multiple user profiles?

How Gemini can help

In addition to the chat interface, Gemini offers a number of entry points that integrate with your development flow:

  • Add generated code with a click: Gemini displays smart actions next to the code it generates, which lets you quickly insert the code into the open editor, insert it into the Android Manifest, or even add required dependencies for popular libraries that are used in the answer.
  • Receive helpful resources: for certain topics, Gemini offers to open the relevant documentation page with further information.
  • Troubleshoot errors: for common errors, Gemini explains what they mean and offers actions to fix them.
  • "Ask Gemini" directly from your codebase: when you select text in the code editor, right-click and select the Ask Gemini action to populate the chat prompt with the selected code. From there you can decide whether or not to send the code—Gemini doesn't send code without your explicit authorization. Ask Gemini is also available to help you troubleshoot warnings and errors in the code editor.

Frequently asked questions (FAQ)

Does Gemini send my code to Google's servers?

Learn about what data is shared and how you can control your privacy settings at Data and privacy.

Does Gemini give accurate and safe responses?

Accelerating people's ideas with generative AI is truly exciting, but it's still early days, and Gemini is an experiment. Some of the responses might be inaccurate, so double-check information in the responses. With your feedback, Gemini is improving. While Gemini has built-in safety controls and clear mechanisms for feedback in line with our AI Principles, be aware that it might display inaccurate information or offensive statements.

Because AI is an evolving technology, it can generate output that sounds plausible but is factually incorrect. We recommend that you validate all output from Gemini before you use it.

Can Gemini help with coding?

Yes, Gemini can help with coding and topics about coding. It is experimental and you are responsible for your use of code or coding explanations. Use discretion and carefully test all code for errors, bugs, and vulnerabilities before relying on it.

How can I reset chat history?

Gemini uses the chat history for additional context when responding to your prompts. If your chat history is no longer relevant to what you're currently trying to achieve, reset the chat history by clicking Reset Chat in the Gemini pane.

Why do I get a "code is blocked" error message?

Gemini conducts multiple layers of checks on model-generated responses. For example, there's a check to ensure that the model-generated code doesn't replicate existing content at length. It's possible that your response gets blocked due to one of these checks. In this case, try again with a different prompt.

How and when does Gemini cite sources in its responses?

Gemini should generate original content and not replicate existing content at length. We've designed our systems to limit the chances of this occurring, and we will continue to improve how these systems function. If Gemini does directly quote at length from a code repository, it cites that source. The citation might also reference an applicable open source license. It is your responsibility to comply with any license requirements.

What terms of service apply to my Gemini usage?

Your use of Gemini is subject to the Google Terms of Service and the Generative AI Additional Terms of Service.

How can I report feedback about Gemini?

We're looking for your feedback to help us improve Gemini responses across all of the domains of Android development. To help, use Gemini in your development workflow and mark its responses as helpful or not helpful using the thumbs up and down options in the Gemini UI. This input helps us identify the areas that need more training.

How is Gemini different from other LLM-powered chatbots?

Gemini leverages an LLM that was designed to help with coding scenarios. Gemini is tightly integrated within Android Studio, which means it can provide more relevant responses, and lets you to take actions and apply suggestions with just a click.

What are some tips for using Gemini?

  • Be clear and concise when you ask your question.
  • Use simple language that Gemini can understand.
  • If Gemini does not understand your question, try rephrasing it.
  • Review Gemini suggestions before using them.

For more details, see Tips for engaging with Gemini.