Skip to content

Getting Started

Run Gemini Nano on Android, on the device, with the Vercel AI SDK. The provider wraps Google’s ML Kit GenAI libraries directly. Android serves the models through AICore, so there’s no model to bundle and no API key.

Feature Model ML Kit API
Text generation android() genai-prompt
Tool calling android(), on Gemini Nano 4 genai-prompt
Embeddings android.embeddingModel() genai-embedding
Transcription android.transcriptionModel() genai-speech-recognition
Terminal window
npm install @react-native-ai/android ai

The provider works with AI SDK v7 and needs its polyfills. Examples with schemas, such as the tools examples, also use zod.

  • Android with minSdkVersion 26 or higher
  • Kotlin 2.4 or newer, which the current ML Kit GenAI libraries are built with
  • React Native 0.76 or newer, with the New Architecture
  • A physical device with AICore support and a locked bootloader. See the ML Kit GenAI documentation for the supported devices. Emulators and device clouds such as Firebase Test Lab have no Gemini Nano.

Install the config plugin:

Terminal window
npx expo install expo-build-properties

Set minSdkVersion and the Kotlin version with expo-build-properties:

{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 26,
"kotlinVersion": "2.4.0"
}
}
]
]
}
}

Then regenerate the native project:

Terminal window
npx expo prebuild --clean

Set minSdkVersion = 26 and kotlinVersion = "2.4.0" in the ext block of android/build.gradle.

Pass android() to the AI SDK. Check that Gemini Nano can run on the device first:

import { android } from '@react-native-ai/android'
import { generateText } from 'ai'
const { availability } = await android.getModelInfo()
// When downloadable, the first request downloads Gemini Nano on its own
if (availability === 'available' || availability === 'downloadable') {
const { text } = await generateText({
model: android(),
prompt: 'Summarize on-device AI in one sentence.',
})
}

Models & Availability covers the availability checks and downloading Gemini Nano.