Skip to content

Repository files navigation

Before you read on, please note:

Starting September 2026, a silent update, nonconsensually pushed by Google, will block every Android app whose developer hasn't registered with Google, signed their contract, paid up, and handed over government ID. More details here: KEEP ANDROID OPEN


This is the sdcpp-on-android project

Purpose:

An interface for Stable Diffusion, with focus on image generation by entering text prompts. This project depends entirely on the excellent work of leejet and his contributors writing the stable-diffusion.cpp project ( https://github.com/leejet/stable-diffusion.cpp ). Many thanks for their efforts! Note that this implementation only uses a small subset (T2I) of sd.cpp's full feature set.

Installation Instructions:

See Build Instructions below. You may need to allow 'Install from unknown sources' when prompted.

Usage Guide:

  • Download at least one valid stable diffusion model file on your device. For details see: https://github.com/leejet/stable-diffusion.cpp/blob/master/docs/sd.md
    Download these safetensors or ckpt files using your favorite web browser and store them below 'Download', but you may want to create a dedicated folder (e.g., 'Download/Models') to stay organized.

  • Grant permissions: Confirm the required storage permissions (see Security & Privacy Note below).

  • Generate an image in three steps The generated image files (PNG) are saved in 'Download' folder, called outputXXXXXXXXXX.png, where XXXXXXXXXX is the Unix timestamp of when the generation started. Also a log file is written, called outputXXXXXXXXXX.log.txt.

Example: Generate an SDXS image (within seconds)

Step 1: first enter some input:
Step 2: wait some seconds:
Step 3: view your result:

Example: an SDXL style image (via SSD1B, needs much more time)

Step 1: first enter some input:
Step 2: wait some time:
Step 3: view your result:

Build Instructions:

Import the project to Android Studio and build it, then execute the built APK on your device by sideloading it via ADB. You also are free to build the native library part by yourself, see below.

License:

MIT, the same license as sd.cpp.

Security & Privacy Note:

This app requires extensive storage permissions to function. It needs to read access to load the model files you provide and write access to save the generated images. We value your privacy and no data is collected or transmitted by this app. You can verify this by reviewing the source code.

Native code:

IMPORTANT: this project contains compiled code forked from sd.cpp (stable-diffusion.cpp-JetsonNano), see here: https://github.com/akleine/stable-diffusion.cpp-JetsonNano/commit/979d9b7 . You are encouraged to build the sd executable yourself using Android NDK, see the sd.cpp build documentation: https://github.com/leejet/stable-diffusion.cpp/blob/master/docs/build.md . The binaries were built in Termux using the following commands:

cmake .. -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=/data/data/com.termux/files/home/android-ndk-r27b/build/cmake/android.toolchain.cmake \
  -DANDROID_PLATFORM=android-28 \
  -DANDROID_ABI=arm64-v8a  # for 32 bit use: armeabi-v7a \
  -DGGML_OPENMP=OFF \
  -DSD_OPENCL=OFF

ninja
cd bin
strip sd

After compiling rename the executables from 'sd' or 'sd-cli' to 'libsd.so' and place it in app/src/main/jniLibs/arm64-v8a respectively app/src/main/jniLibs/armeabi-v7a folder. (This renaming is needed due android restrictions.)

Optional use of an openCL driver:

At first get a current commit from https://github.com/leejet/stable-diffusion.cpp and read more about using openCL (for Adreno GPU) here: https://github.com/leejet/stable-diffusion.cpp/blob/master/docs/build.md Then change the above script to:

cmake .. -G Ninja \
  -DCMAKE_TOOLCHAIN_FILE=/data/data/com.termux/files/home/android-ndk-r27b/build/cmake/android.toolchain.cmake \
  -DANDROID_PLATFORM=android-28 \
  -DANDROID_ABI=arm64-v8a  # for 32 bit use: armeabi-v7a \
  -DGGML_OPENMP=OFF \
  -DSD_OPENCL=ON

ninja
cd bin
strip sd-cli
# patchelf --replace-needed libOpenCL.so.1 libOpenCL.so sd-cli

After compiling rename the executable from 'sd-cli' to 'libsdopenCL.so' and place it near to 'libsd.so' . During execution, this app searches for a file named 'libsdopenCL.so' and suggest using it. Note: libOpenCL.so is not included here. Please compile it yourself, for example try: https://github.com/leejet/stable-diffusion.cpp/commit/d73b419

About

Create images from text using sd.cpp on Android

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages