Skip to main content
Android Code Studio features a fully project-aware AI agent that understands your code, modules, and project structure to provide intelligent coding assistance.

Overview

The AI Agent is more than a code generator - it’s a context-aware assistant that:
  • Understands your project - Analyzes project structure, dependencies, and code
  • Maintains conversation history - Remembers previous interactions
  • Tracks modifications - Records all code changes with undo capability
  • Supports multiple providers - Works with various AI services
  • Writes files directly - Can create and modify files with permission
The AI Agent requires an API key from a supported provider and internet connectivity.

Supported Providers

Android Code Studio supports multiple AI providers:
Claude models by Anthropic
  • Claude 3.5 Sonnet
  • Claude 3 Opus
  • Claude 3 Sonnet
  • Claude 3 Haiku
Setup:
  1. Get API key from console.anthropic.com
  2. In Android Code Studio: Settings → AI Agent → Provider
  3. Select Anthropic
  4. Enter your API key

Getting Started

1

Configure the AI Agent

  1. Open Settings → AI Agent
  2. Select your preferred provider
  3. Enter your API key
  4. (Optional) Choose a specific model
  5. Save settings
2

Open the AI Assistant

Tap the AI Agent icon in the toolbar, or select Tools → AI Agent from the menu.
3

Grant Permissions

On first use, the AI Agent requests permission to:
  • Read your project files
  • Access project structure
  • Modify files (with confirmation)
The AI Agent can write files. Always review changes before accepting.
4

Start Chatting

Type your question or request and press Send.

Project Awareness

The AI Agent analyzes your project to provide contextual assistance:
ProjectData.kt
data class ProjectTreeResult(
    val projectName: String,
    val projectPath: String,
    val modules: List<ModuleInfo>,
    val sourceFiles: List<String>,
    val dependencies: List<String>
)
When you ask for help, the agent knows:
  • Your project structure and modules
  • Available dependencies
  • Existing classes and files
  • Build configuration
  • Package names

Example Interactions

You: "Add a RecyclerView adapter for displaying a list of users"

Agent: Analyzes your project structure, creates:
- UserAdapter.kt in the correct package
- user_item.xml in res/layout
- Adds RecyclerView dependency if missing

File Operations

The AI Agent can create and modify files:

Writing Files

AIAgent.kt:54
fun writeFile(filePath: String, content: String): FileWriteResult
When the agent writes a file:
  1. Permission Check - Asks for your confirmation
  2. Content Preview - Shows what will be written
  3. Write Operation - Creates or updates the file
  4. Verification - Confirms success
You can review and edit suggested code before accepting it.

File Write Results

FileWriteResult.kt
sealed class FileWriteResult {
    data class Success(val path: String) : FileWriteResult()
    data class Failure(val error: String) : FileWriteResult()
    object PermissionDenied : FileWriteResult()
}

Modification Tracking

The agent tracks all modifications:
AIAgent.kt:46-47
fun recordModification(filePath: String, oldContent: String?, newContent: String, success: Boolean)
fun getModificationHistory(): List<ModificationAttempt>

Modification History

data class ModificationAttempt(
    val timestamp: Long,
    val filePath: String,
    val previousContent: String?,
    val newContent: String,
    val attemptNumber: Int = 0,
    val success: Boolean = false
)
View history in Tools → AI Agent → View Modifications.

Review Changes Screen

When the AI agent makes multiple file modifications, Android Code Studio presents a Review Changes interface: Features:
  • File List - See all files modified by the AI agent
  • Diff Preview - View changes side-by-side with syntax highlighting
  • Selective Apply - Choose which changes to accept or reject
  • Summary - Overview of all modifications in the current batch
Actions:
  • Apply All - Accept all suggested changes
  • Cancel - Reject all changes and close the review screen
  • Individual Review - Select each file to review changes before applying
Always review AI-generated code in this screen before applying changes. The agent may make assumptions or introduce errors that need correction.

Undo Changes

Revert unwanted changes:
AIAgent.kt:46
fun undoLastModification(): Boolean
Click Undo in the AI Agent panel or use Edit → Undo AI Changes.

Conversation Management

The AI Agent maintains conversation context:

Clear Conversation

AIAgent.kt:36
fun clearConversation()
To start fresh:
  • Click Clear Chat in the AI Agent panel
  • Or select Tools → AI Agent → Clear Conversation
Clearing the conversation removes context but preserves modification history.

Context Window

The agent maintains recent messages for context:
  • User messages - Your questions and requests
  • Assistant responses - AI-generated answers
  • System messages - Project context and information
  • Modification results - File operation outcomes

Retry Logic

The agent includes automatic retry for failed operations:
AIAgent.kt:49-52
fun resetAttemptCount()
fun incrementAttemptCount()
fun getCurrentAttemptCount(): Int
fun canRetry(): Boolean
Retries occur when:
  • API rate limits are hit
  • Network errors occur
  • Generation fails temporarily
Default: Up to 3 retry attempts

Best Practices

Be Specific

“Create a RecyclerView adapter for User objects with name and email fields, showing a profile picture using Glide”

Provide Context

“In MainActivity, add a button that navigates to the ProfileActivity and passes the user ID”

Review Generated Code

Always review AI-generated code before accepting it. The agent may:
  • Make assumptions about your requirements
  • Use deprecated APIs
  • Introduce bugs
  • Not follow your coding style

Iterate

If the result isn’t perfect:
  1. Provide feedback: “The button should be in the top right corner”
  2. Ask for modifications: “Change this to use Kotlin coroutines instead”
  3. Request explanations: “Why did you use this approach?”

Common Use Cases

“Create a data class for an API response with id, title, description, and timestamp fields”The agent generates:
data class ApiResponse(
    val id: Long,
    val title: String,
    val description: String,
    val timestamp: Long
)
“Add Retrofit and Gson for networking”The agent updates build.gradle.kts:
dependencies {
    implementation("com.squareup.retrofit2:retrofit:2.9.0")
    implementation("com.squareup.retrofit2:converter-gson:2.9.0")
}
“Implement the Repository pattern for user data with Room database”The agent creates:
  • UserEntity.kt
  • UserDao.kt
  • UserRepository.kt
  • AppDatabase.kt
“Fix the crash when rotating the screen in MainActivity”The agent:
  1. Analyzes MainActivity
  2. Identifies lifecycle issues
  3. Suggests ViewModel implementation
  4. Applies the fix
“Optimize this image loading code for better performance”The agent:
  1. Reviews the code
  2. Suggests caching strategies
  3. Recommends using Glide or Coil
  4. Implements the optimization

Permissions

The AI Agent respects user permissions:
AIPermissionManager.kt
enum class PermissionType {
    READ_PROJECT,
    WRITE_FILES,
    EXECUTE_COMMANDS,
    ACCESS_NETWORK
}
Configure permissions in Settings → AI Agent → Permissions:
  • Read Project - Allow reading project files
  • Write Files - Allow creating/modifying files
  • Execute Commands - Allow running Gradle tasks
  • Access Network - Allow API requests
Grant only the permissions you’re comfortable with. You can revoke them anytime.

Limitations

Context Size

Large projects may exceed the model’s context window. Focus requests on specific modules.

API Costs

AI providers charge per request. Monitor usage to control costs.

Network Required

Requires internet connectivity (except for local LLM setup).

Not Always Accurate

AI can make mistakes. Always review generated code.

Troubleshooting

Error: “Invalid API key” or “Authentication failed”Solution:
  1. Verify your API key is correct
  2. Check that the key hasn’t expired
  3. Ensure you selected the correct provider
  4. Re-enter the key in Settings
Error: “Rate limit exceeded”Solution:
  1. Wait a few minutes before retrying
  2. Check your API provider’s rate limits
  3. Consider upgrading your plan
  4. Use retry logic (automatic)
Error: “Context length exceeded”Solution:
  1. Be more specific in your requests
  2. Focus on individual files or modules
  3. Clear conversation and start fresh
  4. Split large requests into smaller ones
Issue: Agent doesn’t respondSolution:
  1. Check internet connectivity
  2. Verify API service is operational
  3. Restart the IDE
  4. Check logs in Build Output

Security & Privacy

Your code is sent to the AI provider’s servers for processing. Be mindful of:
  • Proprietary code
  • API keys and secrets
  • Sensitive data
  • Company policies

Best Practices

  • Don’t share API keys or passwords with the agent
  • Review what data is being sent
  • Use local LLM for sensitive projects
  • Check your organization’s AI usage policy

Advanced Configuration

Model Selection

Choose the right model for your needs:
  • Fast models (GPT-3.5, Claude Haiku) - Quick responses, lower cost
  • Powerful models (GPT-4, Claude Opus) - Better understanding, higher cost
  • Balanced models (Claude Sonnet) - Good balance of speed and quality

Temperature Settings

Adjust creativity vs. accuracy:
temperature = 0.2  // More deterministic, safer for code
temperature = 0.8  // More creative, better for ideas
Configure in Settings → AI Agent → Advanced.

Custom Prompts

Define system prompts for consistent behavior: Settings → AI Agent → System Prompt
You are an expert Android developer. Follow these guidelines:
- Use Kotlin for all code
- Follow Material Design principles
- Include proper error handling
- Add comments for complex logic

Next Steps

Build docs developers (and LLMs) love