๐Ÿ› ๏ธ AI Tools for Android Developers

How to Use Gemini in Android Studio

Gemini in Android Studio can explain a stack trace, draft a Compose preview, write a unit test or run a multi-step change in Agent Mode. It can also confidently produce wrong code. This guide shows the features that save real time, how to prompt them, and how to keep your code and data under control.

โœ๏ธ Yunok Tech ๐Ÿ“… Updated โฑ 7 min read ๐ŸŽฏ Beginner
On this page
  1. Getting started
  2. The features that save the most time
  3. Prompting habits that improve results
  4. Privacy and data control
  5. A verification habit for AI-written code
  6. Real-world use cases
  7. Frequently asked questions
  8. Conclusion

Android Studio now ships with an AI assistant built specifically for Android development. It understands Gradle errors, Compose and Logcat, and it can act across your project in Agent Mode. Used well, it removes a lot of friction. Used carelessly, it adds subtle bugs faster than you can review them.

This guide is for Android developers at any level who want to get practical value from Gemini in Android Studio. It covers the main features, where each one helps most, prompts that produce better results, project rules with AGENTS.md, privacy controls with .aiexclude, and a verification habit that keeps AI-written code safe to ship.

Feature availability changes quickly

Google states that Gemini in Android Studio is available in the latest stable version of Android Studio and in major versions released in the previous 10 months. Feature names and menus below follow the official documentation at the time of writing. Check the overview page for what your version includes.

Getting started

  1. Update Android Studio to the latest stable release.
  2. Open the Gemini tool window (View โ†’ Tool Windows โ†’ Gemini) and sign in with your Google account.
  3. Review the data-sharing settings when prompted. Choose whether Gemini can use your project's code as context, and read the data and privacy page for your tier.
  4. Add an .aiexclude file for anything that must never be shared, such as credentials, keystores and proprietary algorithms. See Privacy and data control below.
TierWhat you get (per Google's overview)
Individual (no cost)A lightweight Gemini model with a smaller context window, suitable for most tasks. Optionally add your own Gemini API key to use other models and pay per token.
Individual with Google OneGoogle One subscribers get added capabilities and higher limits at no extra cost.
BusinessVia Gemini Enterprise or the Google Developer Program: higher quota, central admin controls, data residency and security options such as VPC Service Controls, and code customisation.

The features that save the most time

Where Gemini helps across the Android development loop A loop of five stages: Understand (chat, explain code), Write (code completion, transformations, Compose previews), Test (generate unit tests, Journeys), Debug (Logcat and App Quality Insights crash analysis), and Ship (commit messages, dependency updates). Agent Mode can span several stages. Understandchat, explain Writecomplete, transform Testunit tests, Journeys DebugLogcat, crashes Shipcommits, deps Agent Mode: multi-step tasks across stages
Gemini is most useful when it is woven into each stage of the loop, with you reviewing every output, rather than used as a one-shot code generator.

1. Chat: explain, plan and ask

The chat panel is best for understanding: explaining unfamiliar code, comparing approaches, or planning a change before you write it. You can attach files and images for context. Select code in the editor and ask about it directly.

Prompts that work well in chatText
Explain what this ViewModel does, step by step, and point out any coroutine
cancellation or lifecycle problems. Don't rewrite it yet.

I get "Unresolved reference: collectAsStateWithLifecycle". Which dependency
provides it, and where does it go in libs.versions.toml and build.gradle.kts?

Compare Room and DataStore for storing a list of 50 favourite article IDs.
Recommend one and explain the trade-off in 5 bullet points.

2. Code completion and transformations

Inline completion suggests the next lines as you type. It's most accurate for repetitive or pattern-following code such as mappers, DAO methods and test cases that resemble the ones above them. Code transformations let you select code and describe a change ("convert to a sealed interface", "add KDoc", "make this function main-safe with withContext"), then review a diff before accepting.

3. Agent Mode: multi-step changes

Agent Mode takes a goal, plans steps, reads and edits multiple files, and can run tools such as builds. It asks for your approval according to the permissions you configure. It suits well-scoped tasks with a clear definition of done:

Good Agent Mode tasksText
Add a "Sort by price" option to ProductListScreen. Store the choice in the
existing SettingsRepository (DataStore). Update ProductListViewModel and its
unit tests. Follow the patterns already used for "Sort by name".
Build the app and run the unit tests for the product module when done.

Update all Compose-related dependencies to their latest stable versions using
the version catalog, build the project, and fix compilation errors you
introduce. List every version change in your final summary.
Scope agent tasks tightly

"Refactor the app to Clean Architecture" is a bad agent task: too big to review, with an unclear finish line. Break large changes into small, reviewable steps, commit before each one, and read every diff.

4. Project rules with AGENTS.md

Android Studio supports an AGENTS.md file and rules that give Gemini persistent instructions about your project, so you don't repeat conventions in every prompt. Keep it short, specific and checked into Git:

AGENTS.md (project root)Text
# Project conventions for AI agents

## Stack
- Kotlin only, Jetpack Compose UI, Material 3. No new XML layouts.
- Architecture: ViewModel exposes a single StateFlow<UiState>; UI is stateless where possible.
- DI: Hilt. Networking: Retrofit + kotlinx.serialization. Local data: Room, DataStore.

## Rules
- Add dependencies only through gradle/libs.versions.toml.
- Never put API keys or secrets in source code or BuildConfig.
- Use viewModelScope; never GlobalScope. Inject dispatchers.
- Every new ViewModel needs unit tests in src/test using MainDispatcherRule and fakes (no mocks for repositories).
- User-facing strings go in res/values/strings.xml.

## Verification
- Run ./gradlew :app:testDebugUnitTest before finishing a task.
- Summarise every file changed and why.

5. Generate unit tests

Gemini can generate unit-test scaffolding for a class. Treat the output as a first draft. Check that the tests assert meaningful behaviour, not just that code runs, and that they use your project's fakes and coroutine test rules. A useful prompt is to ask for the edge cases first, then the tests:

Test promptText
List the edge cases for CartViewModel.applyCoupon(): expired coupon, network
failure, empty cart, coupon already applied, double tap. Then write JUnit tests
for each using FakeCouponRepository and MainDispatcherRule from our test utils.

6. Compose previews and UI from images

Gemini can generate Compose previews for a composable with realistic sample data, and generate UI from an attached image such as a design mockup. The result is a starting point: check spacing against your design system, replace hard-coded strings with resources, and verify accessibility (content descriptions, touch target sizes, contrast).

7. Debugging: Logcat and App Quality Insights

From Logcat you can ask Gemini to explain a crash or error. In App Quality Insights, which shows Firebase Crashlytics and Android vitals data in the IDE, Gemini can analyse a crash cluster together with your source code and suggest causes. This is often the highest-value feature for maintaining real apps, because it shortens the path from "top crash on the dashboard" to "likely line of code".

8. Commit messages and housekeeping

Gemini can draft commit messages from your staged diff, and Agent Mode can automate dependency updates. Edit generated commit messages so they explain the why, which a diff alone can't tell the model.

Prompting habits that improve results

Do

  • Give context: files, error text, versions
  • State constraints ("no new dependencies", "keep the public API")
  • Ask for a plan or explanation before code
  • Ask for tests together with the change
  • Iterate in small steps

Avoid

  • Vague asks ("make it better")
  • Huge multi-feature requests
  • Accepting code you can't explain
  • Pasting secrets or customer data into prompts
  • Trusting version numbers without checking release pages

Privacy and data control

Before using AI tools on company code, check your organisation's policy and the tier's data terms. Android Studio gives you two important controls:

  • Project-level context sharing settings decide whether Gemini can use your codebase as context at all.
  • .aiexclude files exclude specific files or directories from being sent as context, using patterns similar to .gitignore.
.aiexclude (project root)Text
# Never share secrets or signing material
*.jks
*.keystore
local.properties
secrets.properties
google-services.json

# Proprietary or regulated code
app/src/main/java/com/example/pricing/engine/
docs/customer-data/
Exclusion is not a security boundary for secrets

.aiexclude controls what is sent as context. Secrets should still never be committed to source control in the first place. Use environment variables, a secrets manager, or Gradle properties outside the repository.

A verification habit for AI-written code

  1. Read the diff line by line. If you can't explain a line, don't merge it.
  2. Check APIs and versions against official docs and release pages. Models sometimes suggest deprecated or non-existent APIs.
  3. Build and run the tests. Add a test for the behaviour you asked for, if the AI didn't.
  4. Check Android specifics that models often miss: lifecycle and configuration changes, main-thread safety, permissions, accessibility, and process death.
  5. Look for security issues: hard-coded keys, logging personal data, disabled TLS checks, exported components.

Real-world use cases

Joining a legacy codebase

Use chat to explain unfamiliar modules and Java classes before changing them. Ask for a sequence of how data flows from API to screen. Verify the explanation by stepping through with the debugger.

Fixing a top crash

Open the crash in App Quality Insights, ask Gemini for likely causes using the stack trace and source, write a failing test that reproduces it, then fix it and confirm the test passes.

Routine dependency upgrades

Let Agent Mode bump versions in the catalog and fix compile errors, then review the summary and diff and run the full test suite before merging.

Frequently asked questions

Is Gemini in Android Studio free?

There is a no-cost individual tier with a lightweight model. You can add a Gemini API key to pay per token for more capable models, and Google offers a business tier with additional controls. Check the overview page for current details.

Does Gemini see my whole project?

Only if you allow code context sharing, and never the files excluded by .aiexclude. Review the data and privacy documentation for your tier.

Should beginners use AI coding tools?

Yes, mainly to explain concepts, errors and code. Writing code yourself first builds the judgement you need to review AI output later.

Can I use other AI assistants in Android Studio?

Android Studio supports other plugins and tools, and Gemini in Android Studio can use MCP servers to extend Agent Mode. The verification habit in this article applies to every tool.

Conclusion

Gemini in Android Studio is most valuable as a context-aware collaborator: explaining code and errors, drafting tests and previews, analysing crashes, and handling well-scoped multi-step changes in Agent Mode. Set it up with AGENTS.md for your conventions and .aiexclude for sensitive files, keep tasks small, and verify everything before it ships.

Next step: add an AGENTS.md to your current project and ask Agent Mode to write unit tests for one ViewModel. Review them critically. If you want to build AI features into your app rather than use AI to write it, start with What Is AI in Android Development?

Official references

๐Ÿ“ฑ Apps built by Yunok Tech

Real Android apps on Google Play, free to download.

See all our apps โ†’

Ready to build real Android applications?

AI coding tools multiply what you already know. The stronger your Kotlin, Compose and architecture foundation, the better you can judge, fix and ship what these tools suggest.

Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.

Explore the Android course and take your next step as an Android developer.

Share: LinkedIn X / Twitter WhatsApp