On this page
- Two meanings of "AI in Android development"
- The landscape: five ways to add AI to an Android app
- Task-specific ML: still the right answer surprisingly often
- On-device generative AI: Gemini Nano
- Cloud generative AI: Gemini via Firebase AI Logic
- Where AI fits in your app architecture
- Real-world use cases and the right tool for each
- Production concerns teams underestimate
- A learning path through this series
- Frequently asked questions
- Conclusion
A product manager asks for "AI in the app". One developer imagines a chatbot. Another thinks of scanning receipts with the camera. A third plans to use AI to write the code faster. All three are "AI in Android development", but they share almost nothing in terms of architecture, cost, privacy or device support.
This guide is the starting point for the Yunoktech Android AI series. It's for Android developers who know Kotlin and want a clear, accurate map of the field: what kinds of AI exist on Android today, where each one runs, what it costs, which Google SDK provides it, and how it fits into a normal app architecture.
Two meanings of "AI in Android development"
- AI as a product feature: something your users experience, such as summarising a document, describing a photo, smart replies, semantic search or a support chat.
- AI as a development tool: assistants such as Gemini in Android Studio that help you write, explain, test and debug code. Your users never see these directly.
Most of this article is about the first meaning. The development-tools side is covered in How to Use Gemini in Android Studio.
The landscape: five ways to add AI to an Android app
Think of the options along two axes: what kind of model (a specialised task model or a general-purpose generative model) and where it runs (on the device or in the cloud).
| Approach | Good for | Network | Cost model | Main limitation |
|---|---|---|---|---|
| โ ML Kit vision/language | OCR, barcodes, face/pose detection, translation, language ID | Not needed (bundled or downloaded models) | No per-request fee | Fixed tasks only, no free-form generation |
| โก LiteRT custom model | Your own classifier, detector or recommender | Not needed | Your training and engineering time | You own the model lifecycle, size and accuracy |
| โข Gemini Nano (ML Kit GenAI) | Summaries, proofreading, rewriting, image descriptions, short prompts | Not needed after model download | No per-request fee | Only on supported devices; beta APIs; foreground only; per-app quota |
| โฃ Cloud Gemini (Firebase AI Logic) | Chat, reasoning, long documents, multimodal input | Required | Per token (free tier available) | Latency, data leaves the device, cost at scale |
| โค Your own backend | Multi-provider, RAG over private data, tools, strict control | Required | Per token + server costs | You build and operate the backend |
Task-specific ML: still the right answer surprisingly often
Before reaching for a large language model, ask whether the problem is really a fixed task. Reading text from a photo, scanning a barcode or detecting a language are solved problems with small, fast, free on-device models. An LLM would be slower, costlier and less predictable at them.
// Dependencies (use the latest versions from the ML Kit release notes):
// implementation("com.google.mlkit:text-recognition:<version>")
// implementation("org.jetbrains.kotlinx:kotlinx-coroutines-play-services:<version>") // for await()
import com.google.mlkit.vision.common.InputImage
import com.google.mlkit.vision.text.TextRecognition
import com.google.mlkit.vision.text.latin.TextRecognizerOptions
import kotlinx.coroutines.tasks.await
class ReceiptScanner {
private val recognizer = TextRecognition.getClient(TextRecognizerOptions.DEFAULT_OPTIONS)
/** Returns all recognised lines, top to bottom. Runs fully on-device. */
suspend fun readLines(bitmap: Bitmap, rotationDegrees: Int = 0): List<String> {
val image = InputImage.fromBitmap(bitmap, rotationDegrees)
val result = recognizer.process(image).await()
return result.textBlocks.flatMap { block -> block.lines.map { it.text } }
}
fun close() = recognizer.close()
}A common and effective pattern combines both kinds: run on-device OCR first, then send only the extracted text, not the photo, to a generative model to categorise the expense. That reduces cost, latency and the amount of personal data that leaves the device.
On-device generative AI: Gemini Nano
Gemini Nano is Google's on-device foundation model. It runs inside AICore, an Android system service that downloads, updates and hardware-accelerates the model, so your APK doesn't carry a multi-gigabyte model file. Apps access it through the ML Kit GenAI APIs: Summarization, Proofreading, Rewriting and Image Description, plus a more flexible Prompt API. At the time of writing these APIs are in beta (speech recognition is alpha), so check the current status before you depend on them.
The key constraints come straight from the official documentation:
- Device support is limited to specific recent devices from several manufacturers. Always call
checkFeatureStatus()before showing the feature. - Inference is allowed only while your app is the top foreground app. Background use, including from a foreground service, is blocked.
- AICore enforces a per-app inference quota, so bursts of requests can return a
BUSYerror. Retry with exponential backoff. - Feature-specific limits apply. For example, summarisation input must be under about 4,000 tokens and supports a small set of languages.
The full walkthrough with code is in Gemini Nano and ML Kit GenAI on Android.
Cloud generative AI: Gemini via Firebase AI Logic
For open-ended chat, complex reasoning, long documents or broad multilingual support, you need a larger cloud model. Google's recommended path for calling Gemini directly from an Android app is the Firebase AI Logic SDK. It supports Kotlin coroutines and Flow, and it integrates with Firebase App Check to help ensure requests come from your genuine app rather than from someone who extracted your configuration.
// build.gradle.kts (app):
// implementation(platform("com.google.firebase:firebase-bom:<latest>"))
// implementation("com.google.firebase:firebase-ai")
import com.google.firebase.Firebase
import com.google.firebase.ai.ai
import com.google.firebase.ai.type.GenerativeBackend
// Model names change frequently: check the current list before release.
private const val MODEL_NAME = "gemini-3.8-flash"
val model = Firebase.ai(backend = GenerativeBackend.googleAI()).generativeModel(MODEL_NAME)
suspend fun suggestTitle(noteText: String): String? =
model.generateContent("Suggest a short, specific title (max 6 words) for this note:\n$noteText").textDon't embed a Gemini, OpenAI or any other provider's secret key in your APK. Anything in an APK can be extracted. Use Firebase AI Logic with App Check, or route requests through your own backend that holds the key and enforces per-user limits. Details are in Gemini API Integration in Android Using Kotlin.
Where AI fits in your app architecture
AI calls are just another data source, and slow, fallible and sometimes costly ones at that. Treat them like a network repository: hide the provider behind an interface, call it from a ViewModel inside a coroutine, and model loading, streaming, success and error as UI state.
/** What the app needs from "AI", independent of the provider. */
interface TextAssistant {
suspend fun isAvailable(): Boolean
suspend fun summarize(text: String): String
}
/** Tries on-device first (private, free), falls back to cloud when unavailable. */
class FallbackTextAssistant(
private val onDevice: TextAssistant,
private val cloud: TextAssistant,
) : TextAssistant {
override suspend fun isAvailable() = onDevice.isAvailable() || cloud.isAvailable()
override suspend fun summarize(text: String): String =
if (onDevice.isAvailable()) onDevice.summarize(text) else cloud.summarize(text)
}If the fallback sends user text to the cloud, users must be told. Your privacy policy and the Play Console Data safety form need to reflect it. Some features should have no cloud fallback at all.
Real-world use cases and the right tool for each
Expense app: scan receipts
- Problem
- Typing receipt totals is tedious.
- Solution
- On-device ML Kit OCR โ optional cloud model to categorise the extracted text.
- Why
- OCR is a fixed task; only small text leaves the device.
- Trade-off
- Categorisation needs a network connection and costs tokens.
Messaging app: polish a reply
- Problem
- Users want quick grammar fixes and tone changes.
- Solution
- ML Kit GenAI Proofreading/Rewriting on Gemini Nano.
- Why
- Private messages stay on the device; low latency; no per-call fee.
- Trade-off
- Only on supported devices, so hide the feature elsewhere or offer an opt-in cloud path.
Learning app: ask questions about course notes
- Problem
- Answers must come from the course material, not the open internet.
- Solution
- Backend RAG: retrieve relevant notes, send them with the question to a cloud model.
- Why
- Grounding in your own content reduces hallucinations.
- Trade-off
- Requires a backend, embeddings and evaluation work.
Production concerns teams underestimate
- Non-determinism. The same prompt can produce different outputs. Design the UI for variation and let users edit or regenerate.
- Hallucinations. Models can state false things confidently. Don't present generated text as verified fact, especially in health, finance or legal contexts.
- Prompt injection. If the model reads untrusted content such as emails or web pages, that content can try to override your instructions. Never let model output trigger sensitive actions without validation or user confirmation.
- Cost and quotas. Cloud costs scale with tokens. On-device has quotas. Add per-user limits, caching and graceful "try again later" states.
- Evaluation. Keep a small set of real test inputs and review outputs whenever you change the prompt or the model version.
- Accessibility and UX. Label AI-generated content, stream long responses so the UI feels responsive, and always provide a non-AI path.
A learning path through this series
- How to Choose the Right AI Model for an Android App: a decision framework.
- Cloud AI vs On-Device AI for Android: deployment trade-offs in depth.
- Gemini API Integration in Android Using Kotlin: your first cloud feature.
- Gemini Nano and ML Kit GenAI on Android: your first on-device feature.
- Build an AI Chatbot with Kotlin and Jetpack Compose: a complete project.
Frequently asked questions
Do I need to know machine learning to add AI to an Android app?
No. ML Kit and Firebase AI Logic expose high-level Kotlin APIs. You need solid Android skills (coroutines, state management, error handling) plus an understanding of model limitations, privacy and cost. Training your own models with LiteRT is where ML knowledge becomes necessary.
Does Gemini Nano work on every Android phone?
No. It requires AICore and supported hardware, and the device list is published on the ML Kit GenAI page. Your app must check feature status at runtime and offer a fallback or hide the feature.
Is it safe to call an AI API directly from the app?
Only through a mechanism designed for it, such as Firebase AI Logic with App Check. Never embed a raw provider API key in the APK. For multi-provider setups or sensitive logic, use your own backend.
Can I use OpenAI or other models in an Android app?
Yes, typically through your own backend that holds the API key and calls the provider. The Android app talks to your backend, which also lets you switch providers later.
What's the difference between ML Kit and ML Kit GenAI?
Classic ML Kit provides task-specific models such as text recognition and barcode scanning. ML Kit GenAI provides generative features such as summarisation and rewriting, powered by Gemini Nano through AICore on supported devices.
Conclusion
AI in Android development isn't one technology. It's a toolbox: task-specific on-device ML for fixed problems, Gemini Nano for private on-device generation on supported devices, and cloud models through Firebase AI Logic or your own backend for heavier reasoning. Whichever you choose, it slots into the same architecture you already know: a repository behind an interface, called from a ViewModel, with honest loading and error states.
Next step: write down one AI feature idea for your app and decide which of the five approaches fits it. Then use the framework in How to Choose the Right AI Model for an Android App to check your choice.
Official references
๐ฑ Apps built by Yunok Tech
Real Android apps on Google Play, free to download.
Walzi4K wallpapers for lock and home screenGet it โธ
NotiVaultNotification history: recover dismissed notificationsGet it โธ
Ready to build real Android applications?
Every AI feature still runs inside an Android app that has to be fast, reliable and well structured. Strengthen the Kotlin, Jetpack Compose and architecture skills that AI integrations depend on, then apply these AI concepts with confidence.
Move beyond theory and strengthen your Android development skills with Yunoktech's Android course. Learn core concepts, practical implementation, modern Android development techniques, and the reasoning behind building maintainable applications.
Explore the Android course and take your next step as an Android developer.