#!/usr/bin/env bash # Cross-compiles libsummarize-llm-jni.so (arm64-v8a) for the summarize feature. # # One-off build on a Linux box with network access (this project was built in # a sandbox with NDK r27c; the Android Studio side does NOT need any NDK). # Run from tools/llama-jni/. Requires: git, cmake >= 3.22, unzip, $ANDROID_NDK # pointing at an extracted NDK (r26+), ANDROID_ABI override optional. # # llama.cpp commit pinned below = the one verified to support arch "gemma4" # (src/llama-arch.cpp LLM_ARCH_GEMMA4). Bump only together with re-running # PC-side prompt validation. set -euo pipefail LLAMA_COMMIT="df03399b885831b2a1603b3abb0d8c156808e363" ABI="${ANDROID_ABI:-arm64-v8a}" PLATFORM="${ANDROID_PLATFORM:-android-24}" OUT_DIR="../../app/src/main/jniLibs/${ABI}" if [ ! -d llama.cpp ]; then git clone https://github.com/ggml-org/llama.cpp fi cd llama.cpp git fetch --depth 1 origin "${LLAMA_COMMIT}" 2>/dev/null || true git checkout "${LLAMA_COMMIT}" 2>/dev/null || git pull cd .. cmake -B "build-${ABI}" \ -DCMAKE_TOOLCHAIN_FILE="${ANDROID_NDK}/build/cmake/android.toolchain.cmake" \ -DANDROID_ABI="${ABI}" \ -DANDROID_PLATFORM="${PLATFORM}" \ -DANDROID_STL=c++_static \ -DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON \ -DCMAKE_BUILD_TYPE=Release cmake --build "build-${ABI}" -j "$(nproc)" mkdir -p "${OUT_DIR}" cp -v "build-${ABI}/libsummarize-llm-jni.so" "${OUT_DIR}/" echo "done -> ${OUT_DIR}/libsummarize-llm-jni.so"