All posts
Edge AI & On-Device ML
Edge AI
Android
Machine Learning
YOLOv8
TensorFlow Lite
ONNX
On-Device AI

Edge AI on Android: Building Real-Time On-Device Intelligence

A deep dive into how Edge AI works on Android — from model selection and runtime formats to full pipeline architecture and native C++ inference. Everything you need to understand before writing a single line of code.

January 1, 2025 21 min read

TL;DR

Edge AI means running machine learning models directly on the device instead of a cloud server — trading a network round-trip for local inference, and trading a training-time model for a compressed runtime one (TensorFlow Lite or ONNX).

This post covers the decisions that come before writing code: which model actually fits a phone (MobileNet SSD vs. YOLOv8 Nano), which runtime format to export to, and the six-stage pipeline every real-time vision app runs — camera frame → conversion → resize/normalize → inference → decode → render — including where a native C++/JNI layer fits in. Part 2 turns this into a working app.

The Evolution of Artificial Intelligence — From Cloud to Edge

For many years, AI applications followed a predictable pattern. A mobile app captured data — an image, a voice command, or sensor information — and sent it to powerful cloud servers for analysis. The cloud performed inference and returned the result back to the device.

This model worked well as network speeds improved and cloud infrastructure became widely available. However, it introduced several fundamental challenges: network latency made real-time experiences difficult, continuous data transfer raised privacy concerns, applications stopped functioning when offline, and infrastructure costs scaled with user growth.

As mobile hardware evolved, a new paradigm began to emerge:

This is what we call Edge AI — running machine learning models directly on local devices such as smartphones, cameras, wearables, and embedded systems. Rather than relying on remote servers, the device itself becomes capable of understanding and responding to its environment.

Platform

Why Android Has Become a Natural Platform for Edge AI

Modern Android devices are no longer just communication tools. They are highly optimized computing systems equipped with multi-core CPUs designed for parallel workloads, GPUs capable of accelerating mathematical operations, and Neural Processing Units built specifically for AI inference.

Combined with lightweight runtime engines, Android has become one of the most accessible platforms for developers exploring Edge AI. What makes Android particularly compelling is the ability to create applications that respond instantly to real-world input — not seconds later through a server response, but immediately on the device itself.

Edge AI Isn’t Just Faster — It Changes How Apps Are Designed

When inference happens locally, the architecture of an application fundamentally changes.

Traditional apps operate in a request-response model:

User ActionServer RequestServer ResponseUI Update

Edge AI applications operate in continuous pipelines:

Sensor DataModelResultVisual FeedbackRepeat

This difference might seem subtle, but it has massive implications for how developers think about data flow, performance, and system design.

Real-World Examples of Edge AI Already Around Us

Even if you’ve never built an Edge AI application, you likely use several every day:

Face unlock systems that recognize you instantly

Smart camera apps that detect scenes in real time

Language translation that works completely offline

Fitness trackers analyzing motion patterns continuously

All of these systems rely on on-device inference pipelines that process data without leaving the device.

Scenario

Imagining a Real Edge AI Application

Understanding Edge AI conceptually is useful, but architecture becomes clearer when anchored to a real scenario. Imagine building an application whose goal is Real-Time On-Device Intelligence — an app that understands what the camera sees and reacts immediately, without internet connectivity.

This application doesn’t simply capture photos. Instead, it continuously observes the world through the device camera and understands what it sees. It might:

Detect everyday objects like chairs, bottles, or phones
Highlight detected items on screen instantly
Operate completely offline
Respond in real time without waiting for a server

Why Object Detection Becomes the Core Use Case

Many AI capabilities exist — classification, segmentation, pose estimation, language models — but for real-time intelligence on Android, object detection becomes one of the most compelling starting points.

Object detection allows an application to:

SeeUnderstandHighlight

Instead of simply saying “this is a photo of a chair,” object detection identifies where objects exist in the scene. This creates a powerful interactive experience — bounding boxes appear around detected items, UI overlays react to the environment, and the device feels aware of the physical world.

From an engineering perspective, object detection is also a perfect introduction to Edge AI because it demonstrates the entire pipeline:

InputPreprocessModelDecodeRender
The First Decision

The First Major Design Decision: Choosing the Model

Before discussing architecture, pipelines, or Android integration, developers must answer a foundational question:

Two popular options often appear in Android Edge AI projects: MobileNet SSD and YOLOv8 Nano. These models represent different philosophies of mobile machine learning, and understanding their differences is crucial because the model choice influences runtime architecture, performance characteristics, complexity of integration, and long-term scalability.

Simplicity-First

MobileNet SSD

Often considered the most beginner-friendly object detection model for Android development. Its design focuses on lightweight computation, stable performance on mobile CPUs, and predictable output formats.

Because it has existed for years, it integrates smoothly with mobile frameworks like TensorFlow Lite, and many tutorials use it as a starting point. Outputs are easier to decode, requiring less post-processing compared to modern YOLO models.

The tradeoff: it may struggle with detecting smaller objects, handling complex scenes, or achieving state-of-the-art accuracy.

Modern Detector

YOLOv8 Nano

Represents a newer generation of object detection models. Rather than prioritizing simplicity, it focuses on higher accuracy, modern architecture design, and flexibility across platforms — while remaining small enough for mobile devices.

This power introduces complexity: unlike MobileNet SSD, YOLOv8 doesn’t directly provide ready-to-draw detections. It produces dense prediction tensors that require additional processing — decoding and Non-Maximum Suppression.

Choose it if you want more impressive visual results, modern detection performance, and deeper control over inference pipelines.

Why Model Choice Should Come Before Architecture

Many beginners start by setting up camera pipelines or Android libraries without first considering the model. This leads to confusion later, because different models expect different preprocessing steps and produce different output structures.

For example, MobileNet SSD integrates easily with TensorFlow Lite and offers straightforward decoding, while YOLOv8 Nano may require custom post-processing and deeper architectural decisions. Choosing the model early helps define how data flows, how inference runs, and how results are interpreted.

In our imagined “Real-Time On-Device Intelligence” app, suppose we choose YOLOv8 Nano because we want modern detection performance and flexibility.

Deployment

From Training Models to Mobile Models: Why Exporting Is Necessary

When you download a model like yolov8n.pt, you may assume it can be used directly inside an Android application. It cannot.

Training models and deployment models live in completely different worlds.

During development, models are trained using frameworks like PyTorch or TensorFlow — powerful but heavy environments designed for experimentation and training large neural networks. A .pt file contains model weights, training graph structures, metadata used during training, and dynamic computation logic. Mobile devices cannot efficiently execute this format. Running a full training framework inside an Android app would dramatically increase app size and consume excessive resources.

So before deployment, the model must be converted into a runtime-optimized format. Think of this step like compiling software:

Software analogy

Source CodeCompiled Binary

In Edge AI

Training Model (.pt)Runtime Model (.tflite / .onnx)

It’s important to understand that exporting is more than just file conversion. During export, dynamic operations may become static graphs, unsupported layers may be rewritten, tensor shapes may be fixed, and precision levels may change. This is why exported models sometimes behave differently from training versions.

Two Major Runtime Formats for Android Edge AI

When exporting a model for Android deployment, two formats commonly appear:

.tflite

TensorFlow Lite was designed specifically for mobile devices. Its goals include reducing model size, optimizing memory usage, providing hardware acceleration, and simplifying Android integration. It feels closer to the Android ecosystem — it integrates naturally with Kotlin or Java and provides prebuilt delegates that allow models to run efficiently on CPUs, GPUs, or specialized neural hardware.

.onnx

ONNX takes a different approach. Rather than targeting a single platform, it aims to be a universal model format that works across desktops, servers, embedded devices, and native mobile engines via ONNX Runtime — a lightweight inference engine for native C++ environments. This flexibility introduces additional complexity: integration often involves native code layers and bridging between Kotlin and C++.

Choosing Between TFLite and ONNX Shapes the Entire Architecture

This decision doesn’t only affect performance — it changes how data flows inside the application.

  • TensorFlow Lite often allows direct integration within Kotlin layers.
  • ONNX Runtime commonly requires a native C++ engine connected through JNI.

If the goal is rapid Android integration with minimal native complexity, TensorFlow Lite provides a straightforward path. If the goal is deeper control and a more native-driven pipeline, ONNX Runtime introduces a different architectural layer. Once a runtime is chosen, the structure of the Edge AI application begins to take shape.

The Pipeline

The Real Edge AI Pipeline — From Camera Frame to Intelligence

Now, you may imagine Edge AI as a simple three-step flow:

CameraModelResult

But in reality, the pipeline is far more layered. Let’s walk through the full flow step by step.

1

Camera Sensor — Where Real-Time Data Begins

The device camera becomes the primary source of information. However, the camera doesn’t produce ready-to-use images. Instead, Android camera systems generate frames in a format optimized for hardware efficiency called YUV. YUV is ideal for camera processing but unsuitable for neural network inference, which is why Edge AI pipelines always begin with a transformation phase.

2

Frame Conversion — Turning Camera Data into AI-Readable Images

Before a model can understand an image, the frame must be converted into RGB color space:

YUV Frame from CameraXRGB Conversion

This conversion is often underestimated. You might think model inference is the slowest part of the system, but in real-time applications, preprocessing can consume a significant portion of computation time. Performance bottlenecks in Edge AI frequently come from image preprocessing rather than the model itself.

3

Resizing and Normalization — Preparing the Model Input

AI models require fixed input sizes. For example, YOLOv8 Nano expects a 640×640 input. Regardless of the camera’s native resolution, every frame must be resized. Neural networks are trained on consistent tensor shapes — variable input dimensions would require dynamic graph execution, which is inefficient on mobile devices.

RGB ImageResize to 640×640Float/Byte Tensor

At this stage, the image becomes a numerical tensor — a structured array of values representing pixel intensities.

4

Model Inference — Where Intelligence Happens

Now the runtime engine — TensorFlow Lite or ONNX Runtime — executes the neural network. The model analyzes the tensor and generates predictions. However, something critical must be understood: the model does NOT produce human-readable detections. Instead, it produces a raw output tensor containing numerical predictions about object positions and class probabilities. This is one of the biggest misconceptions beginners have about object detection — the model is only half the story.

5

Decoding and Non-Maximum Suppression

Raw outputs contain thousands of potential predictions. If we drew every prediction on screen, the result would be chaotic. A decoding stage translates model outputs into structured detections:

Raw Output TensorDecode + NMSList<Detection>

This stage involves interpreting bounding box coordinates, calculating confidence scores, and filtering overlapping boxes using NMS. It’s also where model-specific logic lives — MobileNet SSD decoding is relatively straightforward, while YOLOv8 decoding requires more processing because it produces dense predictions.

6

Rendering — Turning Data into Visual Feedback

Once detections are prepared, they are passed back to the UI layer. The app draws visual overlays on top of the camera preview:

List<Detection>Canvas Overlay Draw

From a user’s perspective, this appears as labeled bounding boxes following objects in real time. But internally, this is the final step of a continuous loop.

Edge AI Is a Streaming System — Not a One-Time Process

One of the most important insights in Edge AI development is understanding that the pipeline never stops:

CaptureConvertResizeInferDecodeRenderRepeat ↻

Unlike traditional apps, there is no single “start” and “finish.” Everything happens in a loop, which introduces new engineering challenges: managing memory efficiently, avoiding UI thread blocking, and maintaining smooth frame rates. This is why Edge AI architecture must be modular.

Architecture

Why Modular Architecture Matters

A clean Edge AI application separates responsibilities into independent components:

Camera module

Captures and delivers frames.

Frame processor

Handles format conversion and resizing.

Inference engine

Runs the model.

Detection parser

Decodes raw outputs and applies NMS.

Overlay renderer

Draws results on screen.

This separation allows developers to improve performance without rewriting the entire system. Switching from MobileNet SSD to YOLOv8 only affects the inference layer. Changing from TensorFlow Lite to ONNX affects runtime integration, not UI logic. This modular mindset is essential when building scalable Edge AI applications.

Going Native

Going Deeper: Native Edge AI Architecture on Android

Beyond the general pipeline, some Edge AI applications introduce a native C++ engine for even greater control. Instead of running everything directly inside the Android (Kotlin/Java) layer, inference moves into native code.

Kotlin Meets Native Code: The Role of JNI

Android apps are typically written in Kotlin or Java, but high-performance libraries — including many AI runtimes — are often implemented in C++. To bridge these two worlds, Android uses JNI (Java Native Interface), which acts like a translator:

Android UI Layer (Kotlin/Java)JNI BridgeNative C++ Engine

Through JNI, an app sends camera frames to native code, allows heavy computation to occur there, and returns results back to the UI. JNI exists because native code provides finer control over memory management, lower-level performance optimizations, and easier integration with cross-platform libraries like ONNX Runtime.

Native ONNX Architecture — Layer by Layer

Here’s how the full native architecture looks, end to end:

Kotlin Layer
JNI Bridge
Native C++ Engine
Frame Preprocess
ONNX Runtime Session
Tensor Memory Handling
Post Processing (NMS)
Detection Result Struct
Back to Kotlin UI

Each layer has a specific responsibility:

Kotlin Layer

Manages camera preview, UI rendering, overlay drawing, and lifecycle handling. Rather than running heavy inference directly, it sends frames into the native engine through JNI.

JNI Bridge

Converts Android objects into formats that native C++ code can understand — for example, converting a Bitmap or image buffer into a native memory pointer, and converting detection results back into Kotlin data structures.

Native C++ Engine

Where heavy processing happens. Frame preprocessing occurs here (often using OpenCV or custom logic), the ONNX Runtime loads and executes the model, tensor memory is managed efficiently with reusable buffers, and post-processing including NMS is applied to decode raw predictions.

Detection Results

Packaged into a structured format and sent back through JNI. The Kotlin layer then uses these results to draw overlays on the camera preview. From the user’s perspective, everything appears seamless — but internally, the architecture spans multiple layers.

One common misconception is that ONNX automatically provides faster performance than TensorFlow Lite. In reality, performance depends more on preprocessing efficiency, threading, and pipeline design than on the model format itself. Choosing ONNX should be a strategic decision based on architectural needs — not simply the expectation of higher speed.

Field Notes

The Engineering Reality of Edge AI — Lessons From the Trenches

Real-world Edge AI development introduces challenges that rarely appear in high-level tutorials. Many developers assume the model itself is the most complex part of the system. In practice, most performance and stability issues come from everything around the model.

Performance Bottlenecks Rarely Come from the Model

When you think about optimization, you might focus on the neural network: “Is YOLO faster than MobileNet? Is ONNX faster than TFLite?” But performance issues often originate elsewhere. Consider the full pipeline:

Camera FrameRGB ConversionResizeTensorInferenceDecodeRender

Each stage consumes time. In many Edge AI systems, image conversion and resizing can consume more CPU time than inference itself, inefficient memory allocation can introduce frame drops, and frequent object creation can cause garbage collection pauses. Optimizing only the model rarely solves real-time performance problems.

Resolution Choices Shape the Entire Experience

One of the most impactful decisions in Edge AI design is input resolution. YOLOv8 Nano typically uses 640×640 input — increasing resolution may improve detection accuracy for small objects but increases computational load. Lowering resolution can significantly improve frame rates but may reduce detection precision. This creates a balancing act: Accuracy ↔ Performance. Treat resolution as a design parameter rather than a fixed requirement.

Understanding Model Output Is as Important as Running the Model

Many developers feel successful once the model loads and runs. But raw model output rarely makes sense without interpretation. YOLOv8 outputs dense prediction tensors, confidence scores may require activation functions, and overlapping boxes must be filtered using NMS. The decoding stage is where many real debugging challenges occur. Understanding tensor structure becomes a crucial skill when working with advanced Edge AI models.

Modular Design Prevents Architectural Chaos

As pipelines grow more complex, maintaining clean separation between components becomes essential. Without modular design, small changes cascade into major architectural problems — replacing a model forces you to rewrite UI logic, or changing runtimes breaks preprocessing steps. A modular architecture lets you experiment, optimize, and iterate independently at each layer.

Native vs. Managed Pipelines — A Strategic Choice

Some developers assume native architecture is always better. In reality, the choice depends entirely on project goals. Native pipelines provide deeper memory control and flexibility for custom optimization. Managed pipelines provide faster development cycles, simpler integration, and easier debugging. The best choice isn’t universal — it depends on whether you prioritize performance experimentation or rapid application development.

Edge AI Development Is a Mindset Shift

Perhaps the most important insight is that Edge AI changes how developers think about software. Instead of building static features, developers design systems that continuously interpret the world. This requires thinking in terms of data flow, timing, modular architecture, and real-time responsiveness.

Once this mindset develops, building Edge AI applications becomes less about individual technologies and more about orchestrating a dynamic pipeline.

Recap

Wrapping Up — What You’ve Learned

In this blog, we explored the entire conceptual foundation behind building a Real-Time On-Device Intelligence application on Android:

  • What Edge AI is and why it matters
  • How object detection models shape architecture
  • The differences between MobileNet SSD and YOLOv8 Nano
  • Exporting models into mobile runtime formats (.tflite vs .onnx)
  • Designing a real-time pipeline stage by stage
  • Understanding native vs. managed architectures through JNI
  • The engineering insights that make Edge AI systems truly work

We intentionally focused on understanding before implementation. Without clarity on architecture and data flow, jumping directly into code often leads to confusion.

Coming in Part 2

In the Next Blog…

Now that the full architecture is clear, the next step is to bring this pipeline to life. In the upcoming blog, we’ll move from concepts to implementation and explore:

  • How to structure an Android project for Edge AI
  • Integrating camera pipelines with CameraX
  • Preparing tensors for inference
  • Decoding model outputs into detections
  • Building a real-time overlay system step by step

This next stage will transform everything you’ve learned here into a working Edge AI application. Stay tuned.