IntermediateEnglish14 lectures · 1h 55m

Ship Stable Diffusion in an Android App

ONNX Runtime Mobile in Kotlin and React Native, cross-platform acceleration, an offline assistant capstone and a dual-track benchmark

Watch 3 lectures free

What you'll learn

  • Implement a Stable Diffusion sampling loop, scheduler and tokenizer in Kotlin with ONNX Runtime Mobile
  • Build the same feature in React Native with a native pixel encoder
  • Select execution providers per platform and keep the UI thread responsive
  • Build an offline assistant that chains an LLM prompt expansion into image generation
  • Benchmark native versus React Native fairly and choose a track with data

About this course

On a phone there is no convenient pipeline object: you write the sampling loop, wire the tokenizer, manage tensor lifetimes and stream progress to the user yourself. This course builds that image app twice — in Kotlin and in React Native — and finishes with a capstone and a benchmark.

Track A is Kotlin with ONNX Runtime Mobile: project and Gradle setup, an SdEngine that runs text encoder, U-Net and VAE decoder, the Euler scheduler implemented from the equations, a CLIP byte-pair tokenizer, a ViewModel with streaming progress, a Compose screen, and the NNAPI versus QNN decision. Track B is React Native with onnxruntime-react-native, including a native pixel encoder on Android and iOS and the pain points of the cross-platform path. Then cross-platform acceleration: per-platform execution-provider selection, avoiding JS-thread freezes, iOS Instruments and Perfetto. The capstone chains a small language model that expands the prompt into the image pipeline, with a safety filter and checkpoint resume. The final session is a dual-track benchmark: metrics that are fair, in-app hooks, a CI performance gate, results analysis, and a decision framework for choosing a track.

The code is read by intent, and the narration lists explicitly what must be fixed in the sample code before shipping.

**Licensing — read before you build a business on this.** Putting model weights inside an app is redistribution, so this course ships a `Resources/LICENSES.md` with every asset checked against its actual licence text. Stable Diffusion 1.5 is CreativeML Open RAIL-M: commercial use is allowed, but you must carry its use restrictions through to your own users as an enforceable term. The capstone's image model, **SDXL Turbo, is under the Stability AI Community License — free for commercial use only while you are under US $1,000,000 annual revenue**, and it requires a "Powered by Stability AI" attribution. Gemma 2, which expands the capstone's prompts, requires you to hand every user a copy of the Gemma Terms and to carry its Prohibited Use Policy into your own terms.

Curriculum6 sections · 14 lectures · 1h 55m

Section 0. Welcome

Free preview

Section 1. Track A Native Android Stable Diffusion

Free preview

Section 2. Track B React Native Stable Diffusion

  • 🔒track b kickoff ort rn setup sdservice pipeline8:48
  • 🔒native pixel encoder sd screen track b pain points8:48

Section 3. Cross-Platform Acceleration

  • 🔒rn ep selection fallback chain qnn workarounds8:24
  • 🔒js thread freezes benchmark chart instruments perfetto comparison8:12

Section 4. Capstone Offline Assistant

  • 🔒capstone architecture and llm prompt expansion8:06
  • 🔒sdxl turbo safety filter end to end porting rules8:06
  • 🔒kotlin orchestrator events checkpoint resume8:36

Section 5. Dual-Track Benchmark and Wrap-up

  • 🔒benchmark metrics fairness and logging schema8:06
  • 🔒memory probes adb device farm and ci gate8:24
  • 🔒results analysis track decision and course finale8:18

Requirements

  • · A computer with Python 3.10+ (a free Google Colab account is enough for most sessions)
  • · Comfort reading Python code; you do not need to be an expert
  • · Exported Stable Diffusion components in ONNX form (our Profiling and Export course, or your own)
  • · Android Studio (Track A) and/or a React Native toolchain (Track B)
  • · Kotlin or TypeScript basics; you can follow one track only
  • · Willingness to read `Resources/LICENSES.md` before you ship: the capstone runs on SDXL Turbo, which is free commercially only under US $1M annual revenue

Who this is for

  • · Android and React Native developers adding on-device image generation
  • · Teams comparing a native and a cross-platform stack for AI features
  • · Engineers who want a capstone project rather than isolated snippets

Read alongside the course

    The voice-over in this course is synthesized with a text-to-speech model from scripts written and reviewed by the instructor, and the on-screen material (notebooks, code, slides) is the instructor's own work.

    Ship Stable Diffusion in an Android App | SOTAAZ Blog