# Build ONNX Runtime Generate() API

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/)
- [Create a development environment](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/1-dev-env-setup/)
- [Build ONNX Runtime](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/2-build-onnxruntime/)
- [Build ONNX Runtime Generate() API](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/3-build-onnxruntime-generate-api/)
- [Run a benchmark on an Android phone](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/4-run-benchmark-on-android/)
- [Build and run an Android chat app](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/5-build-android-chat-app/)
- [Next Steps](https://learn.arm.com/learning-paths/mobile-graphics-and-gaming/build-android-chat-app-using-onnxruntime/_next-steps/)

## Cross-compile the ONNX Runtime Generate() API for Android CPU
The Generate() API in ONNX Runtime is designed for text generation tasks using models like Phi-3. It implements the generative AI loop for ONNX models, including:
- pre- and post-processing
- inference with ONNX Runtime
- logits processing
- search and sampling
- KV cache management. You can learn more by reading the [ONNX Runtime generate() API page](https://onnxruntime.ai/docs/genai/).

### Clone onnxruntime-genai repo
Within your Windows PowerShell prompt, checkout the source repo:
```
C:\Users\$env:USERNAME
git clone https://github.com/microsoft/onnxruntime-genai
cd onnxruntime-genai
git checkout 5ba9fce5b52452a82b12ac343d941765c430d996
```
> **Note:** You might be able to use later commits. These steps have been tested with the commit `5ba9fce5b52452a82b12ac343d941765c430d996`. This corresponds to ORT Gen API 0.9.0

### Build for Android CPU
Ninja generator is used to build on Windows for Android. Make sure you have set JAVA_HOME before running the following command:
```
python -m pip install requests
python3.13 build.py --skip_wheel --build_java --android --android_home C:\Users\$env:USERNAME\AppData\Local\Android\Sdk --android_ndk_path C:\Users\$env:USERNAME\AppData\Local\Android\Sdk\ndk\27.3.13750724 --android_abi arm64-v8a --config Release
```
When the build is complete, confirm the shared library has been created:
```
ls build\Android\Release\libonnxruntime-genai.so
ls build\Android\Release\src\java\build\android\outputs\aar\onnxruntime-genai-release.aar
```
