Build for Android (Experimental)
Step-by-step instructions for cross-compiling llama.cpp for Android (ARM64) for use with GenAI Llama’s embedded inference.
Prerequisites
- Android NDK (r25 or later recommended)
- Included with Android Studio, or download standalone from developer.android.com/ndk
- CMake 3.14 or later
- Git
Set the ANDROID_NDK environment variable to point to your NDK installation:
export ANDROID_NDK=/path/to/android-ndk-r25c
Choose Your GPU Backend
| Backend | Best For | Flag |
|---|---|---|
| Vulkan | Most modern Android devices (recommended) | -DGGML_VULKAN=ON |
| CPU | Older devices, or testing | (no GPU flag) |
Vulkan Support
Most Android devices released since 2017 support Vulkan. For maximum compatibility with older devices, build with CPU-only as a fallback.
Build Steps
1. Clone llama.cpp
git clone https://github.com/ggml-org/llama.cpp.git
cd llama.cpp
git checkout b3600 # or any later release tag
2. Configure and Build
Vulkan (Recommended)
cmake -B build \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-26 \
-DBUILD_SHARED_LIBS=OFF \
-DGGML_VULKAN=ON
cmake --build build --config Release
CPU Only
cmake -B build \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=arm64-v8a \
-DANDROID_PLATFORM=android-26 \
-DBUILD_SHARED_LIBS=OFF
cmake --build build --config Release
Important
Always use arm64-v8a as the ABI. This matches the ARM64 architecture required by modern Android devices and Unreal Engine's Android target.
3. Copy Libraries
Copy all .a files from build/ (and its subdirectories) into your plugin directory:
<YourProject>/Plugins/GenAILlama/ThirdParty/LlamaCpp/lib/Android/
find build -name "*.a" -exec cp {} /path/to/ThirdParty/LlamaCpp/lib/Android/ \;
4. Rebuild Your Unreal Project
After placing the files, rebuild your Unreal project targeting Android. Check the build log for:
GenAILlama: llama.cpp libraries found at <path>. Embedded inference enabled.
Model Size Considerations
Mobile devices have limited RAM and no swap. Choose models carefully:
| Model | Q4_K_M Size | RAM Usage (Approx.) | Recommended For |
|---|---|---|---|
| Qwen2.5-0.5B | ~400 MB | ~600 MB | Low-end devices |
| TinyLlama 1.1B | ~637 MB | ~900 MB | Mid-range devices |
| Gemma-2B | ~1.4 GB | ~2 GB | High-end devices |
Set GPU Layers = 0 (CPU only) if you encounter GPU memory issues on specific devices.
Troubleshooting
CMake can’t find the NDK toolchain
- Verify
ANDROID_NDKpoints to the correct directory. - The toolchain file should be at
$ANDROID_NDK/build/cmake/android.toolchain.cmake.
Vulkan build fails
- Ensure your NDK version includes Vulkan headers (NDK r21+ includes them).
- Try building with CPU-only first to isolate the issue.
App crashes on older devices
- Check that the device supports the minimum Android API level (26).
- Try reducing
GPU Layersor using CPU-only inference.
See Also
- Embedded Inference Setup — Overview and troubleshooting
- GenAI Llama Documentation — Full plugin reference