页面简介
ML Kit's GenAI APIs, powered by Gemini Nano, offer high-level interfaces for Android apps to perform on-device generative AI tasks, leveraging AICore for enhanced functionality and user privacy.
正文摘录
Android Developers Develop AI Guides Send feedback Gemini Nano Gemini Nano lets you deliver rich generative AI experiences without needing a network connection or sending data to the cloud. On-device AI is a great solution for use-cases where low cost and privacy safeguards are your primary concerns. For on-device use-cases, you can take advantage of Google's Gemini Nano foundation model. Gemini Nano runs in Android's AICore system service, which leverages device hardware to enable low inference latency and keeps the model up-to-date. ML Kit GenAI APIs ML Kit's GenAI APIs harness the power of Gemini Nano to help your apps perform on-device generative AI tasks. These APIs are built on top of AICore, an Android system service that enables on-device execution of GenAI foundation models to facilitate features such as enhanced app functionality and improved user privacy by processing data locally. Learn more. Key features ML Kit organizes its GenAI capabilities into the following categories: Custom generation and agents Work directly with the Gemini Nano foundation model for custom use cases: Direct model access (using the GenerativeModel class): Generate text or typed structured output from custom text-only or multimodal prompts, or manage your own multi-turn chat history directly by using a List<Content> object with USER and MODEL roles and a sessionId value. Agentic workflows (using the AgentRunner class): Built on top of the GenerativeModel class, automating multi-turn session management (including in-memory conversation history) and multi-step tool-calling loops. Speech and audio Transcribe, translate, and synthesize speech audio on-device: Speech Recognition: Transcribe spoken audio content into text in the same language. Speech Translation: Translate spoken audio into text in another language in real time. Text to Speech: Synthesize natural-sounding speech audio from text. Text and image tasks Use task-specific APIs optimized for common vision, writing, and search tasks through a high-level interface: Image Description: Generate a short description of a given image. Summarization: Summarize articles or conversations as a bulleted list. Proofreading: Proofread short chat messages. Rewriting: Rewrite short chat messages in different tones or styles. Semantic Search: Generate vector embeddings for text and images using the Embedding API and pair them with AndroidX AppSearch to find content by meaning. Use an Android skill to integrate and optimize the ML Kit Prompt API in your app. To install the skill from the Android CLI, run: android skills add ml-kit-genai-prompt-api Architecture through AICore As a system-level module, you access AICore through a series of APIs in order to run inference on-device. In addition, AICore has several built-in safety features, ensuring a thorough evaluation against our safety filters. The following diagram outlines how an app accesses AICore to run Gemini Nano on-device. Figure 1. AICore serves as the interface between your app and the Gemini Nano model, managing model updates and safety while leveraging on-device hardware. Keep user data private and secure On-device generative AI executes prompts locally, eliminating server calls. While this removes network latency, inference speed depends on device hardware. This approach enhances privacy by keeping sensitive data on the device, enables offline functionality, and reduces inference costs. AICore adheres to the Private Compute Core principles, with the following key characteristics: Restricted Package Binding: AICore is isolated from most other packages, with limited exceptions for specific system packages. Any modifications to this allowed list can only occur during a full Android OTA update. Indirect Internet Access: AICore does not have direct internet access. All internet requests, including model downloads, are routed through the open-source Private Compute Services companion APK. APIs within Private Compute Services must explicitly demonstrate their privacy-centric nature. Additionally, AICore is built to isolate each request and doesn't store any record of the input data or the resulting outputs after processing them to protect user privacy. Read the blog post An Introduction to Privacy and Safety for Gemini Nano to learn more. Figure 2. The AICore architecture manages input and output safety, request processing, and model weights to provide a secure environment for on-device AI. Benefits of accessing AI foundation models with AICore AICore enables the Android OS to provide and manage AI foundation models. This significantly reduces the cost of using these large models in your app, principally due to the following: Ease of deployment: AICore manages the distribution of Gemini Nano and handles future updates. You don't need to worry about downloading or updating large models over the network, nor impact on your app's disk and runtime memory budget. Accelerated inference: AICore leverages on-device hardware to accelerate inference. Your app gets the best performance on each device, and you don't need to worry about the underlying hardware interfaces. When to use hybrid inference Although Gemini Nano is ideal for offline and privacy-sensitive tasks, it has on-device constraints such as token limits, device hardware limitations, and model capability boundaries. In these scenarios, you can use hybrid inference to balance AI workloads between the local device and the cloud. To ensure a consistent user experience across all devices and handle complex queries, you can use the Firebase AI Logic Hybrid API. This lets your app do the following: Fall back gracefully: Automatically route requests to Gemini Flash or Gemini Pro models in the cloud when Gemini Nano is unavailable or unsupported on the user's device. Enforce security: Protect cloud inference with Firebase App Check (and its supported attestation providers, like Play Integrity) and keep sensitive system prompts server-side. Send feedback Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates. Last updated 2026-10-29 UTC.