← Agentic / Android CLI: Deep Dive
📊 Chapter 01

The Paradigm Shift

The Android CLI replaces fragmented legacy tooling with a single binary purpose-built for AI agents. Structured JSON output instead of verbose human-readable logs fundamentally changes how LLMs consume Android context — and the numbers prove it.

Token consumption drops ~70% by replacing XML dumps and verbose Gradle traces with structured JSON.

AI-assisted development speeds increase up to 3× by eliminating the context wall and reducing hallucinations.

70%
Fewer tokens consumed
Faster dev velocity
1
Unified binary
🧱 Chapter 02

Breaking the Context Wall

Historically, agents were forced to use tools built for humans. Toggle between the two realities below to understand the paradigm shift at the core of the Android CLI.

The Overwhelmed Agent

📉
Verbose Logs

Feeding an LLM a 400-line Gradle stack trace burns through tokens rapidly and obscures the actual error signal in noise.

🗑️
Context Loss

Dumping massive nested activity_main.xml files into a prompt causes the agent to lose its place in the view hierarchy entirely.

😵‍💫
Hallucinations

Legacy binaries (adb, avdmanager) produce unstructured text, leading agents to invent UI components that don't exist.

🔄 Chapter 03

Real-World Workflow

A concrete walkthrough of autonomously migrating a legacy XML view to modern Jetpack Compose using the Android CLI. Click through each step to follow the agent's full execution path.

Equip with Required Skills

Inject expert knowledge into the agent's context before writing a single line of code. This ensures it follows current architectural best practices — using ComposeView as a bridge — instead of attempting a dangerous full-screen rewrite.

# List available skills android skills list # Inject the migration skill android skills add --agent=claude-code \ --skill=migrate-xml-views-to-jetpack-compose

Capture Current UI State

Instead of reading a raw nested XML file, the agent captures the actual rendered state of the screen in the emulator. This returns a token-efficient JSON map of the live UI hierarchy — only what matters, stripped of visual noise.

# Capture current screen as structured JSON android layout --pretty
The --pretty flag formats the JSON for readability. Omit it in automated pipelines for raw compact output.

Strategic Prompting

Target specific elements from the JSON output to prevent hallucinations. Use View IDs or component types — never "migrate the whole screen" in one shot.

Example Prompt (by file & ID):

"Open res/layout/item_tenant_bill.xml. Migrate only the ConstraintLayout with ID @+id/rent_payment_card to Jetpack Compose. Leave the rest intact and use a ComposeView bridge."
Pro Tip: Always instruct the agent to list the specific View IDs it plans to replace before it writes code. This checkpoint allows human confirmation before irreversible changes are made.

Execute & Verify the Delta

Once the code is written, the agent rebuilds and checks the layout diff to verify the semantic visual structure remains identical. A minimal diff confirms a successful migration.

# Build and deploy ./gradlew assembleDebug android run --apks=app/build/outputs/apk/debug/app-debug.apk # The game changer: verify visual integrity android layout --diff
If --diff returns minimal or zero changes, the migration preserved visual parity.
🛠️ Chapter 04

Command Reference

The essential Android CLI commands, grouped by purpose. Click the copy icon on any block to grab commands directly for your terminal or agent workflow.

Environment & Init

Scaffold modern projects without wrestling with missing SDKs.

android init android sdk install platforms/android-35 build-tools/35.0.0 android create --output=./App --name=App empty-activity-agp-9
Emulator Management

Spin up virtual devices for visual inspection effortlessly.

android emulator create --list-profiles android emulator create --profile=medium_phone android emulator start medium_phone
Installation (macOS, Apple Silicon)

Get the preview CLI running locally.

curl -fsSL https://dl.google.com/android/cli/latest/darwin_arm64/install.sh | bash android updates android info
Knowledge Base Queries

Access live developer docs to bypass stale LLM training data.

android docs search 'Jetpack Compose LazyColumn memory optimization' android docs search 'WorkManager chaining constraints API 2.9'
Layout Inspection & Diffing

The core superpower — structured UI inspection without XML noise.

android layout --pretty # structured JSON of current screen android layout --diff # delta between last two snapshots android layout --filter=id # filter output by view ID android layout --filter=type # filter output by component type
🏗️ Chapter 05

Under The Hood

Three architectural pillars distinguish the Android CLI from legacy binaries: live Retrieval-Augmented Generation for docs, a composable Skill system for agentic workflows, and open-standard agent integration.

🧠
RAG-on-the-Fly

The android docs command is a local entry point for Retrieval-Augmented Generation — returning summarised context from live Google Developer blogs to prevent deprecated API usage in generated code.

🎯
Skill Architecture

Skills are Agentic System Prompts stored in open-standard markdown. They define Context (e.g., MVVM), Constraints (e.g., don't touch manifest), and Execution logic — injected per-task, not globally.

🤝
Multi-Agent Support

Built on open standards. Integrates seamlessly with Claude Code, Gemini CLI, and Codex. Any custom agent following the skill spec is compatible.

AGENT INTEGRATION MATRIX
Claude Code
✓ Full Support
Gemini CLI
✓ Full Support
Codex
✓ Full Support

Any custom agent following the open skill specification is also compatible.