跪拜 Guibai
← All articles
AI Programming · JetBrains · Android

AppFunctions Is Android's On-Device MCP, Letting Gemini Call Your App's Code Directly

By Carson带你学Android ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

AppFunctions turns every Android app into a local tool server for on-device AI. Apps that skip it will be invisible to Gemini in voice scenarios, while those that integrate gain a zero-tap user path that reuses existing code rather than demanding a new backend.

Summary

AppFunctions is a Jetpack library, KSP compiler, and OS-level registry that standardizes how Android apps expose their capabilities to AI agents like Gemini. It mirrors the Model Context Protocol (MCP) but runs locally on the device, reusing the app's existing state, database, and business logic instead of requiring a separate backend. A developer annotates functions with @AppFunction, writes KDoc that doubles as the AI's prompt, and registers a service; Gemini can then invoke those functions directly in response to voice commands.

The protocol sidesteps the latency, privacy, and integration overhead of cloud-based tool-calling. Because it hooks into the app's own process, an agent calling addExpense() hits the same Room database and repository layer the UI uses. The trade-off is that KDoc quality directly determines call accuracy, and all functions default to the UI thread, so IO work must be explicitly dispatched.

Google positions this as the fourth major distribution paradigm shift on Android, following push notifications, deep links, and widgets. Apps that don't expose AppFunctions become invisible to Gemini in voice-driven workflows, making integration a competitive requirement rather than an experiment.

Takeaways
AppFunctions is an Android Jetpack library, KSP compiler, and OS registry that exposes app functions to on-device AI agents like Gemini.
KDoc comments on annotated functions are compiled into XML schema and serve as the AI's tool description; sloppy comments cause parameter errors.
All AppFunctions execute on the UI thread by default; database or network calls must switch to Dispatchers.IO to avoid ANRs.
Integration requires three steps: add the alpha10 dependency, annotate serializable data models and functions, and register an AppFunctionService.
ADB commands and a graphical Testing Agent let developers verify registered functions and simulate conversation flows without writing custom tests.
Google's Jetpacker sample app exposes expense recording, itinerary management, and voice notes—functions where speaking is faster than tapping.
Multi-step workflows requiring user choices are deferred to A2UI and ADK Agentic Workflow, not AppFunctions.
Three adoption tiers: expose the top 3 frequent functions, expose the full data layer, or refactor the app's architecture to be function-first.
Conclusions

AppFunctions inverts the cloud MCP model: instead of rebuilding backend logic on a server, the agent calls into the app's existing Room database, DI graph, and repository layer directly.

KDoc becomes a runtime AI prompt, which forces a documentation discipline that most Android teams have never practiced—comments now have a direct production impact on call accuracy.

The UI-thread default is a sharp edge that will catch early adopters; it reflects the fact that AppFunctionService is just an Android Service, not a coroutine-aware context.

Google is drawing a hard line between single-turn tool calls (AppFunctions) and multi-step agentic workflows (A2UI/ADK), which suggests a two-tier architecture for AI-driven apps.

The competitive dynamic mirrors past platform shifts: apps that ignored push notifications or deep links lost distribution; apps that ignore AppFunctions risk becoming invisible to the primary voice interface.

Concepts & terms
MCP (Model Context Protocol)
An open protocol that lets LLMs discover and invoke tools, originally designed for cloud servers exposing APIs over a network.
AppFunctions
Google's Android platform API and Jetpack library that brings MCP-style tool exposure to on-device apps, letting AI agents call annotated functions directly.
KDoc
Kotlin's documentation comment format. With AppFunctions, KDoc is compiled into XML schema and used as the AI agent's function description, making comment quality a runtime concern.
KSP (Kotlin Symbol Processing)
A compile-time code generation tool that processes AppFunction annotations and generates the XML schema and service subclasses automatically.
Agentic Workflow
A multi-step AI orchestration pattern where an agent makes decisions across several turns, distinct from single-call AppFunctions. Google addresses this with A2UI and ADK.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗