Skip to content

How to Run llama.cpp on Android (2026): Termux, llama-server and NDK Builds

7–10 minutes
Woman in a sunny cafe holding a tablet with a LLAMA.CPP ANDROID card, hook LLM on your phone

Chat apps make it easy to run a small model on a phone. But if you want the real llama.cpp tools, with llama-cli, llama-server, any GGUF from Hugging Face and full control over threads and context, you can run them natively on Android. There is no root and no cloud involved.

This guide covers the three official routes. The first is the one-command Termux package. The second builds from source inside Termux.

The third cross-compiles with the Android NDK and pushes the binaries over adb. You will also see which models fit in phone RAM, how to serve an OpenAI-compatible API from the phone, how GPU backends work, and how to fix crashes. It follows the llama.cpp and Termux sources as of December 2026.

TL;DR

  • Fastest: install Termux, then pkg install llama-cpp (64-bit phones only).
  • Run a model: llama-cli -hf ggml-org/gemma-3-1b-it-GGUF -c 4096.
  • Serve an API: llama-server -m ~/model.gguf -c 4096, then open http://127.0.0.1:9931 in the phone browser.
  • Keep context small (around 4096) or Android may kill Termux.
  • Models: 1B to 4B at Q4_K_M suit most 6 to 12 GB phones.
  • App developers: use examples/llama.android in Android Studio.

Which Route Should You Pick?

Route Effort Best for
Termux package (pkg install llama-cpp) 2 minutes Most people; easy updates
Build in Termux 10 to 30 minutes Latest commit, custom build flags
NDK cross-compile + adb Needs a PC and the Android NDK Developers, testing on many devices
Android Studio (llama.android) Needs Android Studio Building your own chat app

If you just want a friendly chat app with no terminal, our guide to running an LLM on your phone covers apps like PocketPal. This guide is for the command-line tools.

Install Termux

Termux is a free Linux terminal for Android that needs no root. The llama.cpp docs note the Google Play version is experimental, so install it from F-Droid or the Termux GitHub releases page instead.

  1. Install Termux from F-Droid or github.com/termux/termux-app/releases.
  2. Open it and update packages:
    pkg update && pkg upgrade -y
  3. Optional: allow storage access so you can reach your Downloads folder:
    termux-setup-storage

Your phone needs a 64-bit (arm64) Android build. The Termux llama.cpp package excludes 32-bit ARM and x86, since llama.cpp relies on 64-bit sizes.

Option 1: Install the llama-cpp Package

Termux ships llama.cpp as a ready-made package, built from official llama.cpp release tags and updated automatically.

pkg install llama-cpp

That installs llama-cli, llama-server and the other tools on your PATH. Check it:

llama-cli --version

The package is built with Vulkan and OpenCL support loaded as separate backends. To try GPU offload, also install one of the suggested backend packages:

pkg install llama-cpp-backend-vulkan
# or, for Adreno GPUs
pkg install llama-cpp-backend-opencl

The package also links libcurl, so the -hf flag can download models straight from Hugging Face.

Option 2: Build From Source in Termux

Build yourself when you want the newest commit or your own flags. These are the steps from the llama.cpp Android docs.

  1. Install build tools:
    apt update && apt upgrade -y
    apt install git cmake libandroid-spawn
  2. Clone the repo:
    git clone https://github.com/ggml-org/llama.cpp
    cd llama.cpp
  3. Build with CMake:
    cmake -B build
    cmake --build build --config Release -j 4

    -j 4 uses four cores. More jobs build faster but can overheat a phone or run out of memory.

  4. Find the binaries in build/bin/, for example ./build/bin/llama-cli.

Keep the phone plugged in during the build. For the full list of CMake options, see our llama.cpp install guide.

Pick a Model That Fits

Android shares RAM between apps, and the system will kill Termux if a model plus its context uses too much. Rough guidance for Q4_K_M GGUF files:

Phone RAM Model size to try Notes
4 to 6 GB 0.5B to 1.5B Close other apps first
8 GB 1B to 3B Good balance of speed and quality
12 GB and up 3B to 8B Expect fewer tokens per second on 7B to 8B

The llama.cpp docs recommend keeping models in Termux’s home folder (~/) for the best performance, rather than shared storage. Download one with curl:

curl -L https://huggingface.co/USER/REPO/resolve/main/model-Q4_K_M.gguf -o ~/model.gguf

Or let llama.cpp fetch it. The -hf flag takes a repo name and picks the Q4_K_M file by default:

llama-cli -hf ggml-org/gemma-3-1b-it-GGUF

Chat With llama-cli

llama-cli -m ~/model.gguf -c 4096 -t 4
  • -c 4096 sets the context size. The docs warn that leaving it unlimited can spike memory and kill the terminal, so start at 4096.
  • -t 4 sets CPU threads. Phones mix fast and slow cores; try 4 first, then compare with 6 or 8.
  • Add -p "your prompt" for a one-shot answer.

If you built from source, run ./build/bin/llama-cli from the llama.cpp folder instead.

Run llama-server on Your Phone

llama-server gives you a built-in web chat and an OpenAI-compatible API, right on the phone.

  1. Start the server:
    llama-server -m ~/model.gguf -c 4096

    By default it listens on 127.0.0.1:9931, so only apps on the phone can reach it.

  2. Open the web UI in your phone browser at http://127.0.0.1:9931.
  3. Use the API from any app or script that speaks the OpenAI format, with the base URL http://127.0.0.1:9931/v1.
  4. Reach it from your PC (optional): start it with --host 0.0.0.0 --port 8080, then browse to the phone’s Wi-Fi IP on port 8080. Do this only on a network you trust, and add --api-key to require a key.

You can point Open WebUI on your PC at the phone, as shown in our Open WebUI with llama.cpp guide, or force structured replies with our llama.cpp JSON output guide.

Android may pause Termux when the screen turns off. Run termux-wake-lock (or use the Termux notification’s wake lock) to keep the server alive.

GPU Backends and Arm Speedups

  • CPU (default): works on every arm64 phone. The Android build detects your CPU features at runtime and picks the fastest compatible kernels.
  • KleidiAI: Arm’s optimised CPU microkernels. The Android Studio example turns them on automatically for arm64-v8a; for command-line NDK builds, add -DGGML_CPU_KLEIDIAI=ON.
  • OpenCL: GPU acceleration on recent Qualcomm Adreno GPUs.
  • Vulkan: available through the Termux backend package; results vary a lot by phone driver. See our llama.cpp Vulkan guide.
  • Hexagon: a backend for Snapdragon NPUs with its own build steps in the llama.cpp repo.

Check what llama.cpp can see with llama-cli --list-devices, then offload layers with -ngl. If GPU output is slower or garbled, drop back to CPU, which is often the most reliable choice on phones.

Option 3: Cross-Compile With the NDK

Developers can build on a PC and push to a phone over USB debugging.

  1. Install the Android SDK and NDK and set ANDROID_NDK to the NDK root.
  2. Configure a portable arm64 build from the llama.cpp folder:
    cmake -S . -B build-android \
      -DCMAKE_BUILD_TYPE=Release \
      -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
      -DANDROID_ABI=arm64-v8a \
      -DANDROID_PLATFORM=android-28 \
      -DGGML_CPU_KLEIDIAI=ON \
      -DGGML_NATIVE=OFF \
      -DGGML_OPENMP=OFF \
      -DGGML_LLAMAFILE=OFF \
      -DLLAMA_OPENSSL=OFF
  3. Build and install:
    cmake --build build-android --config Release -j8
    cmake --install build-android --prefix ./android-install --config Release
  4. Push to the phone:
    adb shell "mkdir /data/local/tmp/llama.cpp"
    adb push ./android-install /data/local/tmp/llama.cpp/
    adb push model.gguf /data/local/tmp/llama.cpp/
  5. Run it in adb shell:
    cd /data/local/tmp/llama.cpp
    LD_LIBRARY_PATH=lib ./bin/llama-simple -m model.gguf -c 4096 -p "Hello"

Why the flags: GGML_NATIVE=OFF is required because your PC’s CPU is not the phone’s CPU; OpenMP, llamafile and OpenSSL are off because the NDK’s stable API does not include them. LD_LIBRARY_PATH=lib is needed because Android will not find the bundled libraries on its own.

Do not add a global -march flag unless you want to drop support for older phones.

Build an Android App

To ship llama.cpp inside your own app, import examples/llama.android into Android Studio, run a Gradle sync and build. The binding detects the device’s CPU features (up to SME2 on Arm) and loads matching kernels automatically, so it runs on both new flagships and older phones.

The sample app shows the three core steps: read GGUF metadata, load a model through the AiChat facade to get an InferenceEngine, and stream tokens back as a Kotlin Flow. Arm also publishes a fuller app built on it, Arm AI Chat, on Google Play.

Troubleshooting

Termux closes or the process is “Killed”

You ran out of memory. Lower -c, pick a smaller model or quant, and close other apps.

“Unable to locate package llama-cpp”

Run pkg update. If it still fails, your Termux may be the old Play Store build or a 32-bit device; reinstall from F-Droid.

Build fails with spawn errors

Install libandroid-spawn as shown in Option 2, then rebuild in a clean build folder.

Very slow generation

Try different -t values, use Q4_K_M instead of Q8, and keep the phone cool; thermal throttling cuts speed fast.

“cannot locate symbol” or missing .so over adb

Prefix the command with LD_LIBRARY_PATH=lib from the install folder.

The server stops when the screen locks

Enable termux-wake-lock and exclude Termux from battery optimisation in Android settings.

FAQ

Can llama.cpp run on Android?

Yes. Install it in Termux with pkg install llama-cpp, build it in Termux, or cross-compile with the NDK.

Do I need root?

No. Termux and adb’s /data/local/tmp both work without root.

What is the best model for a phone?

A 1B to 4B instruct model at Q4_K_M is the sweet spot for most phones. Larger models fit only on 12 GB+ devices.

Does llama.cpp use the phone GPU?

It can, through OpenCL on Adreno or Vulkan, but CPU is the most reliable. Test both with --list-devices and -ngl.

Can I use my phone as an LLM server?

Yes. Run llama-server and connect from the phone, or from your PC with --host 0.0.0.0 on a trusted network.

Does it work on iPhone?

Not through Termux. On iOS, use an app built on llama.cpp instead.

How does this compare with Ollama?

llama.cpp is the engine many local apps use under the hood. See Ollama vs LM Studio vs llama.cpp.

Sources

Free weekly email

Get new AI guides every week

One short weekly email with our newest local AI, ComfyUI and AI tool guides. No spam, no pop-ups, just the good stuff.

Free. Unsubscribe anytime in one click. We only use your email to send this newsletter. See our privacy policy.

Woman in a sunny cafe holding a tablet with a LLAMA.CPP ANDROID card, hook LLM on your phone