●NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaply●OMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflows●AGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactions●MEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuously●THROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and region●DEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20●NANOLITE — Nano Banana 2 Lite is here: Google's fastest and most cost-efficient Gemini Image model, made for running lightweight image generation cheaply●OMNIFLASH — Gemini Omni Flash is in public preview, a natively multimodal model that lets enterprises and developers build custom, dynamic video workflows●AGENTS — Managed Agents expand with background: true for async server-side runs and polling, remote MCP server integration, and refreshing credentials across interactions●MEMORY — The Memory Bank IngestEvents API is generally available, decoupling event ingestion from memory generation so you can stream content continuously●THROUGHPUT — Provisioned Throughput now lets you submit up to seven pending orders for the same model and region●DEPRECATE — Image generation models shut down on August 17, and the Grok 4.1 family on the Gemini Enterprise Agent Platform on August 20
A practical look at Gemini in Android Studio, backed by measurements from indie development. Learn how to choose between Code Assist completion, Agent Mode MVVM scaffolding, test generation, and debugging.
Gemini AI has rapidly become an essential part of the Android development workflow. Google has deeply integrated Gemini into Android Studio, delivering capabilities that span code generation, refactoring suggestions, automated test creation, and even autonomous development through Agent Mode.
Having built Android apps for years as an indie developer, I noticed the time I spent on Kotlin boilerplate and writing tests dropped sharply once Code Assist and Agent Mode landed. Whether you're enabling Gemini for the first time or already using completion but want to go further, I'll lay out the ways I actually rely on it, with practical code examples throughout.
This article is designed for developers who meet the following criteria.
You build Android apps with Kotlin and Jetpack Compose
You want to integrate AI coding assistance into your daily workflow
You've used basic code completion but want to explore Agent Mode and other advanced features
Setting Up Gemini in Android Studio
Prerequisites
To use Gemini features, you need the latest stable version of Android Studio (Narwhal or later) and a Google account sign-in.
Here's how to get started.
Open Android Studio and navigate to File → Settings → Tools → Gemini
Check the "Enable Gemini" option
Sign in with your Google account (Workspace accounts may require administrator approval)
Select your preferred model (Gemini 2.5 Pro is recommended; Gemini 2.5 Flash is available for faster responses)
Choosing the Right Model
Android Studio lets you switch between models depending on the task at hand.
Gemini 2.5 Pro: Best for complex refactoring, architecture discussions, and large-scale code generation
Gemini 2.5 Flash: Ideal for inline completions and quick questions where response speed matters most
Gemini 3.1 Pro (Preview): The latest model with improved reasoning accuracy — worth trying if available
You can change your model at any time from Settings → Tools → Gemini → Model.
✦
Thank you for reading this far.
Continue Reading
What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.
WHAT YOU'LL LEARN
✦A decision framework for choosing between Code Assist, Agent Mode, and test generation, grounded in real indie-dev measurements
✦A checklist for scaffolding and reviewing a full MVVM stack safely with Agent Mode
✦Context and token tips that aren't in the official docs but decide completion quality
Secure payment via Stripe · Cancel anytime
✦
Unlock This Article
Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.
After several months of using Gemini inside Android Studio, I realized that completion quality and token consumption depend less on which model you pick and more on how you feed it context. Here are the adjustments that actually moved the needle in my own indie projects.
The single biggest factor in completion accuracy was keeping related files open.
Code Assist includes your open tabs as context. When editing a ViewModel, keeping its UiState and Repository open at the same time makes suggestions noticeably sharper. In my setup, whether related files were open or closed shifted the share of Compose-screen first suggestions I could use as-is by roughly 40%.
Next, prompts that state not just what but under which constraints dramatically cut rework.
Prompt style
Result
"Build a search screen"
Generic UI that needs reworking to match existing patterns
"Build a search screen. State via StateFlow, UI in Jetpack Compose, matching the existing MVVM"
When you want to keep token usage down, avoid pulling entire huge files into context. Keeping a file over 1,000 lines open while leaning on chat made responses slower and mixed in suggestions from unrelated code. Extracting just the target function into a separate file, or selecting a range before asking, keeps both response speed and accuracy stable.
Code Assist Basics — Inline Generation and Completion
Inline Completion
The most fundamental Gemini Code Assist feature is inline completion. As you type, Gemini reads the surrounding context and suggests what you should write next.
// A composable that displays a product list using Jetpack Compose@Composablefun ProductList(products: List<Product>) { LazyColumn( modifier = Modifier.fillMaxSize(), contentPadding = PaddingValues(16.dp) ) { items(products) { product -> ProductCard(product = product) } }}// Gemini also suggests the ProductCard implementation@Composablefun ProductCard(product: Product) { Card( modifier = Modifier .fillMaxWidth() .padding(vertical = 8.dp), elevation = CardDefaults.cardElevation(defaultElevation = 4.dp) ) { Column(modifier = Modifier.padding(16.dp)) { Text( text = product.name, style = MaterialTheme.typography.titleMedium ) Spacer(modifier = Modifier.height(4.dp)) Text( text = "$${product.price}", style = MaterialTheme.typography.bodyLarge, color = MaterialTheme.colorScheme.primary ) } }}
Press Tab to accept a suggestion and Esc to dismiss it. Completion accuracy improves as your project grows, since Gemini draws context from all open files, dependencies, and existing code patterns.
The Chat Panel
The Gemini chat panel on the right side of Android Studio lets you ask questions about your code in natural language.
Here are some effective prompts to try.
"Refactor this ViewModel to support Hilt injection"
"Write a Room database Migration from version 1 to 2 that adds an email column to the users table"
"Add a preview for this composable"
The chat automatically includes the content of your currently open file as context, so you don't need to copy-paste code.
Code Transformation and Refactoring
Java to Kotlin Conversion
When converting Java code to Kotlin, Gemini goes beyond simple syntax translation and suggests idiomatic Kotlin patterns.
Gemini excels at converting legacy XML layouts into Jetpack Compose. Simply reference an XML file in the chat panel and ask "Convert this XML layout to Compose" to get Material Design 3-compliant composables.
// Compose code converted from an XML ConstraintLayout@Composablefun UserProfileScreen(user: User) { Column( modifier = Modifier .fillMaxSize() .padding(24.dp), horizontalAlignment = Alignment.CenterHorizontally ) { AsyncImage( model = user.avatarUrl, contentDescription = "Profile image", modifier = Modifier .size(120.dp) .clip(CircleShape), contentScale = ContentScale.Crop ) Spacer(modifier = Modifier.height(16.dp)) Text( text = user.displayName, style = MaterialTheme.typography.headlineMedium ) Text( text = user.email, style = MaterialTheme.typography.bodyMedium, color = MaterialTheme.colorScheme.onSurfaceVariant ) }}
Agent Mode — Your Autonomous AI Development Partner
What Is Agent Mode?
Agent Mode is the most advanced Gemini Code Assist feature. While standard Code Assist acts as a passive assistant that answers questions, Agent Mode autonomously executes changes across multiple files based on your instructions.
To enable Agent Mode, select "Agent" from the mode switcher at the top of the Gemini chat panel.
Practical Example — Automatic MVVM Architecture Scaffolding
Give Agent Mode instructions like the following, and it will create and edit the necessary files automatically.
"Add a product search feature:
- Use the Repository pattern to call a Retrofit API
- Manage state with StateFlow in the ViewModel
- Create a Jetpack Compose search screen
- Set up DI with Hilt"
Agent Mode generates the following files based on these instructions.
ProductRepository.kt — API calls and caching logic
SearchViewModel.kt — Search state management
SearchScreen.kt — UI composable
NetworkModule.kt — Hilt module updates
build.gradle.kts — Required dependency additions
Each change is shown in a preview where you can approve or reject modifications file by file.
Tips for Getting the Most Out of Agent Mode
Follow these guidelines to maximize Agent Mode effectiveness.
Specify your tech stack explicitly: Mention libraries like "Retrofit + Moshi + Coroutines"
Reference existing patterns: Say "Follow the same MVVM pattern used in other screens in this project"
Give instructions incrementally: Breaking tasks into steps ("First create just the Repository layer" → "Now the ViewModel") yields better results than requesting everything at once
Agent Mode is powerful, but because it rewrites several files at once, skipping review lets unexpected side effects slip in. Here's the routine I follow every time I have it scaffold an MVVM stack.
Branch before generating: Split off a working branch before handing control to Agent Mode, so you can roll everything back even if the diff grows large
Approve file by file: Avoid "approve all," and read the contents of build-affecting files like build.gradle.kts before approving them
Check added dependencies: Always inspect the libs.versions.toml diff to confirm proposed dependencies don't clash with your existing version catalog
Build right after generating: Run ./gradlew assembleDebug immediately after approval to catch compile errors before moving to the next instruction
Attach tests: Follow up with "Write unit tests for this class too" to pin down the generated behavior
In my setup, scaffolding the 4-5 files of a Repository, ViewModel, Compose screen, and Hilt module together completes in roughly 40-60 seconds on the first pass. On average only 1-2 files need touch-ups, mostly minor mismatches with naming conventions or existing patterns. Reducing those mismatches is exactly what the specific prompting above is for.
Test Generation and Debugging
Automated Unit Test Creation
Gemini can generate appropriate unit tests from any class or method. Open the file you want to test and ask "Write unit tests for this class" in the chat.
// Example test code generated by Gemini@OptIn(ExperimentalCoroutinesApi::class)class SearchViewModelTest { @get:Rule val mainDispatcherRule = MainDispatcherRule() private lateinit var viewModel: SearchViewModel private val repository: ProductRepository = mockk() @Before fun setup() { viewModel = SearchViewModel(repository) } @Test fun `search returns products when query is valid`() = runTest { // Given val products = listOf( Product(id = 1, name = "Pixel 9", price = 99800), Product(id = 2, name = "Pixel Watch 3", price = 49800) ) coEvery { repository.search("Pixel") } returns Result.success(products) // When viewModel.onSearchQueryChanged("Pixel") advanceUntilIdle() // Then val state = viewModel.uiState.value assertEquals(2, state.products.size) assertFalse(state.isLoading) assertNull(state.error) } @Test fun `search shows error when repository fails`() = runTest { // Given coEvery { repository.search(any()) } returns Result.failure(IOException("Network error")) // When viewModel.onSearchQueryChanged("test") advanceUntilIdle() // Then val state = viewModel.uiState.value assertTrue(state.products.isEmpty()) assertNotNull(state.error) }}
Logcat Analysis for Debugging
Gemini integrates with Android Studio's Logcat to analyze crash logs and stack traces, presenting root causes and suggested fixes. When an error appears in Logcat, select the error message, right-click, and choose "Ask Gemini."
For example, given an IllegalStateException: Fragment not attached to a context, Gemini provides the following.
The root cause (an async operation completed after the Fragment was already detached)
Concrete fix code (adding isAdded checks, using viewLifecycleOwner.lifecycleScope)
Best practices to prevent similar bugs in the future
Gradle Configuration and Dependency Management
Gemini also assists with build.gradle.kts editing. When you want to add a new library, ask "Add the Coil 3 dependency" in the chat, and Gemini suggests the appropriate entries while considering compatibility with your version catalog (libs.versions.toml).
// Suggested additions to libs.versions.toml// [versions]// coil = "3.1.0"//// [libraries]// coil-compose = { group = "io.coil-kt.coil3", name = "coil-compose", version.ref = "coil" }// coil-network-okhttp = { group = "io.coil-kt.coil3", name = "coil-network-okhttp", version.ref = "coil" }// build.gradle.kts (app)dependencies { implementation(libs.coil.compose) implementation(libs.coil.network.okhttp)}
When version conflicts arise, Gemini can suggest Resolution Strategies and provide compatibility information between library versions.
Frequently Asked Questions
Q: Is Gemini Code Assist free to use?
The core Gemini Code Assist features integrated into Android Studio are free with a Google account, though there are daily request limits. For higher quotas and advanced features, consider the Google AI Pro plan ($19.99/month).
Q: Can I trust the quality of Gemini-generated code?
Gemini generates reasonably high-quality code because it understands your project's context. However, you should always review generated code and run tests before merging into production. Human review is especially critical for security-sensitive areas like authentication, encryption, and network communication.
Q: Can I use Gemini features offline?
Currently, Gemini Code Assist requires a cloud connection. In offline environments, only basic code completion (Android Studio's pre-existing local completion) works. Gemini Nano-powered on-device inference may come to Android Studio in the future, but there's no official announcement yet.
Q: What if Agent Mode makes unwanted changes?
All Agent Mode changes are previewed as Git diffs, and you can approve or reject each file individually. If you accidentally approve a change, you can restore the previous state using Android Studio's Local History (VCS → Local History → Show History).
Key Takeaways
The integration of Gemini into Android Studio has the potential to dramatically streamline your Android development workflow. The recommended approach is to start with inline completions, progress to interactive chat-based development, and then explore Agent Mode for autonomous assistance.
I hope this proves useful in your own development. Thank you for reading.
Share
Thank You for Reading
Gemini Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.