跪拜 Guibai
← Back to the summary

Android CLI Gives AI Agents Structured Access to Build, Debug, and Deploy Workflows


theme: smartblue highlight: xcode

000.png

For a long time, Android development has largely revolved around Android Studio.

Open the IDE, click Build, launch the emulator; when you hit a problem, search the docs in a browser, and when you need a new SDK, open the SDK Manager to install it.

But over the last two years, the development approach has been changing. With the rapid advancement of AI, UI-based development tools have actually become less efficient. Compared to CLI tools, AI is much better at using the CLI to complete complex tasks. So, Google quickly developed the Android CLI.

The new Android CLI brings many capabilities that previously depended on Android Studio into the terminal. It's not just another command-line tool; it is gradually becoming a unified entry point for developers and AI coding agents to understand, build, debug, and automate Android projects.

If you are using Gemini CLI, Claude Code, Cursor, Codex, or other AI programming tools that run in the terminal, you should pay closer attention to the Android CLI. It allows AI to integrate into the Android development workflow in a structured way, rather than just being able to read code and execute a few scattered shell commands.

This article will introduce what the Android CLI is and cover some practical commands useful in most scenarios.

Yes, I know, most developers will definitely say: now that we have AI, do we still need to know these things?

My answer is: although AI is more proficient and makes fewer mistakes than us when executing CLI commands, understanding how CLI tools operate is still crucial for grasping your project's build process, dependencies, and debugging methods. The way the toolchain works is itself part of your project knowledge—the better you understand how your project runs, the better you can collaborate with AI, rather than handing everything over to AI and hoping it doesn't make mistakes.

In other words, understanding how AI uses tools is also important to us! In most cases, we even need to guide AI on how to use the tools.

Why Android CLI is Needed

Modern software development is increasingly leaning towards the terminal.

Developers use these every day:

In comparison, Android development has lagged somewhat in this area. Although Android itself provides many command-line tools, many operations still require Android Studio.

The Android CLI fills this gap.

By learning this CLI, we no longer need to frequently switch between the IDE, browser, SDK Manager, and Device Manager. Many Android-related operations can now be done directly in the terminal.

Installing and Initializing the Android CLI

Installation is actually very simple:

https://developer.android.com/tools/agents?hl=zh-cn

After installing the Android CLI, first initialize the current environment:

android init

This command completes the basic setup for the Android CLI and simultaneously installs the Android CLI Skill for AI Agents.

This way, AI programming tools that support Skills can know what capabilities the Android CLI provides and how to use these commands.

Creating an Android Project

Creating a project with the Android CLI is simple:

android create

If you don't want to actually create files yet and just want to see what operations this command will perform, you can use --dry-run:

android create --dry-run

To see the currently supported project templates, run:

android create --list
0.png This allows you to preview and try different templates without having to create a project, check the result, and then delete it each time.

Searching the Official Android Documentation

The built-in documentation search in the Android CLI is one of my favorite features.

Previously, when encountering a problem, we usually had to open a browser and search for relevant information via Google. Now you can search directly in the terminal:

android docs search "Compose Styles"

The first time you run it, the tool will download the knowledge base:

1.png

Afterwards, it will find the relevant documentation:

2.png

Once you find the document you need, use the returned kb:// address to fetch the content:

android docs fetch kb://...

Developers can use this method to directly access official Android documentation in the terminal, and AI Agents can also call the same commands.

This is very powerful.

AI doesn't have to rely entirely on the Android knowledge already in the model; it can actively query official resources while performing tasks.

Of course, for developers, reading documentation in the console is not as user-friendly:

3.png

Managing Android Emulators

0001.png

When you need to start an emulator, you no longer have to open Android Studio's Device Manager every time.

View available emulators:

android emulator list

Create an emulator:

android emulator create

Start a specific emulator:

android emulator start medium_phone

Stop a running emulator:

android emulator stop emulator-5554

These commands are well-suited for writing automation scripts and are also great for CI environments without a graphical interface.

Quickly Deploying APKs

If you already have a compiled APK, you can deploy it directly to a device via the Android CLI:

android run --apks=app-debug.apk

Additionally, you can:

When frequently building and testing an app, this method can save a lot of repetitive operations.

Managing the Android SDK

Previously, installing or updating the Android SDK usually required going into Android Studio's SDK Manager. Now these operations can also be done via the command line.

View SDK packages:

android sdk list

Install packages:

android sdk install platforms/android-34 build-tools/34.0.0

Installs the latest versions of the Android SDK Platform 34 and SDK Build Tools 34.0.0 packages from the official channel.

Update packages:

android sdk update

Remove packages:

android sdk remove

This way, the entire SDK management process can be scripted.

This is especially useful for automated build environments. CI doesn't need to rely on developers pre-configuring the SDK in a graphical interface; instead, scripts can explicitly declare which components need to be installed.

Taking Screenshots

If you need to capture a device screen for documentation or test reports, run:

android screen capture

You can also have the Android CLI automatically annotate the UI elements in the image:

android screen capture --annotate

Annotated interface elements are easier for programs to reference and can also help AI Agents understand what controls are on the screen and their approximate locations.

Inspecting the Current UI Structure

If you want to view the UI hierarchy of the current page, use:

android layout

Format the output:

android layout --pretty

You can also export the interface hierarchy as a JSON file:

android layout --output hierarchy.json

This feature can be used for:

Compared to just providing a screenshot, a structured interface hierarchy can provide more information to programs and AI.

Android Skills

One of the most noteworthy features in the Android CLI is Android Skills.

Skills can provide AI Agents with Android-related knowledge and workflows.

View currently available Skills:

android skills list

The current skills are:

wear-compose-m3
edge-to-edge
navigation-3
adaptive
android-intent-security
camerax
r8-analyzer
android-cli
testing-setup
perfetto-sql
perfetto-trace-analysis
play-billing-library-version-upgrade
engage-sdk-integration
display-glasses-with-jetpack-compose-glimmer
appfunctions
verified-email
styles
migrate-xml-views-to-jetpack-compose
agp-9-upgrade

So many.

I've been paying more attention to styles and navigation-3 recently.

Search for a Skill:

android skills find performance

Install a Skill:

android skills add

Install or update all Skills:

android skills add --all

If relying only on general model knowledge, AI might use outdated APIs or provide implementations that don't follow current Android best practices.

Android Skills can provide Agents with more specific Android development guidance, helping them complete tasks in the officially recommended way.

In fact, using the latest technology is currently a minor difficulty for Coding Agents. I also use Agents like Codex for coding myself. Previously, without using skills, the Styles API adaptation wasn't very good. Unless you, as a developer, could point out the problem, it wouldn't look at the Styles API source code to fix it; the default adaptation work was not well done.

Connecting with Android Studio

The truly powerful aspect of the Android CLI is that it can communicate directly with a running Android Studio.

First, check the connection status:

android studio check

Analyze errors and warnings in a file:

android studio analyze-file

Find symbol declarations:

android studio find-declaration

Find all usages of a symbol:

android studio find-usages

Open a file in Android Studio:

android studio open-file

Render a Compose Preview:

android studio render-compose-preview

Query dependency library versions:

android studio version-lookup

Previously, these operations usually required developers to perform them manually in the IDE. Now, they can be invoked via commands, meaning scripts and AI Agents can also use some of Android Studio's capabilities.

What This Means for AI

0003.png

The Android CLI gives AI some capabilities that general-purpose AI lacks.

We can make requests like this to an AI coding assistant:

Find all usages of this Composable in the project.

Or:

Render this Compose Preview.

Another example:

Search the official Android documentation for Navigation Compose.

And:

Check if the project's dependencies are outdated.

Previously, AI might only be able to search project text or infer answers based on existing knowledge.

Now, it can obtain structured information from the project, Android Studio, and official documentation via the Android CLI, and then answer questions based on real results.

This is mainly to enable AI to work better:

Taking the First Step

If you are just starting with the Android CLI, you can try these commands first:

android docs search
android emulator start
android layout
android run
android studio check
android studio find-usages
android studio render-compose-preview
android skills add

They are all closely related to daily Android development and will quickly demonstrate the value of the Android CLI.

The Android CLI is Still Evolving

The Android CLI seems very much like laying the foundation for a new way of Android development.

As AI gradually enters developers' daily workflows, development tools need to provide more than just documentation and text output; they also need to offer stable, clear, structured capabilities that can be called programmatically.

The Android CLI is doing exactly this.

It allows developers and AI Agents to interact with Android projects through well-defined commands, rather than all operations relying on developers clicking within the IDE.

In the future, the connection between Android Studio, AI coding assistants, and the terminal will likely become increasingly tight.

A Few Thoughts

The Android CLI is not just a command-line tool launched for convenience.

It is also an important step towards the AI-ification of Android development.

Whether you are:

The Android CLI is worth spending time to understand.

The terminal is gradually becoming a first-class entry point for Android development, and the Android CLI is driving this process.

Comments

Top 1 of 3 from juejin.cn, machine-translated. The original thread is authoritative.

check_null

Already using it, dumping layout info is useful.

RockByte

Right now a small problem for me is that AI generally won't use this on its own; I have to tell it to use it... Looks like I need to copy some skill descriptions into the project-level prompt.

check_null  → RockByte

You need to hit certain keywords. Normally I have to actively tell it to use it before it does, unless you globally declare to prioritize looking for functionality in the CLI.