How to Install LiteRT: Complete Setup Guide for Docker, Bazel, and CMake
You can install LiteRT by building from source using Docker for a hermetic environment, Bazel for native build control, or CMake for lightweight compilation, with the Docker method being the fastest path requiring only a single script execution.
LiteRT is Google AI Edge’s high-performance runtime for on-device machine learning and generative AI. This guide explains how to install LiteRT from the google-ai-edge/LiteRT repository, covering three distinct build approaches that all produce the same core artifacts including libLiteRtRuntime.a and the benchmark_model utility.
Installation Methods Overview
The repository supports three build strategies targeting different development needs:
- Docker – Provides a fully hermetic Ubuntu 24.04 environment with Bazel 7.4.1, Android SDK/NDK, and Python 3.11 pre-installed. Ideal for reproducible builds without host dependency management.
- Bazel – The native build system offering fine-grained control over GPU/NPU delegates, custom toolchains, and cross-compilation for Android or iOS. Requires installing Bazelisk.
- CMake – A lightweight alternative for host builds (Linux/macOS) and straightforward Android cross-compilation. Requires CMake ≥ 4.0.1 and Clang ≥ 17.
All methods share common configuration logic through configure.py, which probes the host environment and writes build-specific settings.
Method 1: Docker Hermetic Build (Recommended)
The Docker approach eliminates environment drift by building inside a container defined in docker_build/hermetic_build.Dockerfile.
Clone the repository and execute the build script:
git clone https://github.com/google-ai-edge/LiteRT.git
cd LiteRT
./docker_build/build_with_docker.sh
The script performs the following actions:
- Builds the
litert_build_envimage containing Ubuntu 24.04, Bazel 7.4.1, and Android toolchains. - Generates
.litert_configure.bazelrcinside the container viaconfigure.py. - Compiles the default target
//litert/cc:litert_compiled_modeland the benchmark tool//litert/tools:benchmark_model. - Copies artifacts from the container’s
bazel-bin/directory back to your host.
Advantages: Zero host dependencies, consistent across macOS, Linux, and Windows (with Docker Desktop).
Limitations: Requires Docker daemon running and sufficient disk space for the image.
Method 2: Bazel Native Build
For developers needing custom flags or specific delegate configurations, building directly with Bazel provides maximum flexibility.
Step 1: Install Bazelisk
Bazelisk automatically manages the correct Bazel version (7.4.1 for this repository):
curl -LO https://github.com/bazelbuild/bazelisk/releases/latest/download/bazelisk-linux-amd64
chmod +x bazelisk-linux-amd64
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
Step 2: Configure the Workspace
Run the interactive configuration script that detects Python paths, Android SDK/NDK locations, and hardware acceleration options:
./configure
This executes configure.py, which writes .litert_configure.bazelrc containing action-environment variables like PYTHON_BIN_PATH and ANDROID_NDK_HOME consumed by the BUILD rules in litert/ and tflite/.
Step 3: Build Targets
Compile the core runtime and tools:
# Core compiled-model library
bazel build //litert/cc:litert_compiled_model
# Benchmark utility for performance testing
bazel build //litert/tools:benchmark_model
Add platform-specific configurations using flags like --config=android_arm64, --config=windows, or --config=cuda as defined in the generated .bazelrc files.
Method 3: CMake Build (Host and Android)
CMake offers a lighter alternative for host development and Android cross-compilation without the full Bazel toolchain.
Host Build (Linux/macOS)
From the repository root:
cd litert
cmake --preset default
cmake --build cmake_build -j
The default preset (defined in CMakePresets.json) configures a Release build using the top-level CMakeLists.txt.
Android arm64 Cross-Compilation
Set the NDK path and use the Android preset:
export ANDROID_NDK_HOME=/absolute/path/to/android-ndk-r27
# Configure host tools for FlatBuffers code generation
cmake --preset android-arm64 \
-DTFLITE_HOST_TOOLS_DIR="$(cd ../host_flatc_build/_deps/flatbuffers-build && pwd)"
cmake --build cmake_build_android_arm64 -j
Enable hardware acceleration by adding flags like -DLITERT_ENABLE_GPU=ON or -DLITERT_ENABLE_NPU=ON to the preset command. The CMakeLists.txt propagates these to the compiler flags for the Core Runtime in litert/.
Verifying Your Installation
Confirm the build succeeded by running the benchmark tool against a TensorFlow Lite model:
./bazel-bin/litert/tools/benchmark_model \
--model=/path/to/model.tflite \
--num_threads=4
The utility outputs latency statistics for CPU, GPU, and detected NPU delegates, confirming that libLiteRtRuntime.a and dispatch libraries built correctly.
Summary
- Docker provides the fastest installation path via
./docker_build/build_with_docker.sh, requiring no local toolchain setup. - Bazel offers maximum configuration control through
./configureandbazel build //litert/cc:litert_compiled_model, managed viaconfigure.pyand.litert_configure.bazelrc. - CMake supports lightweight host builds using
cmake --preset defaultand Android cross-compilation viacmake --preset android-arm64withANDROID_NDK_HOMEset. - All methods produce identical artifacts in
bazel-bin/orcmake_build*directories, including thebenchmark_modelvalidation tool.
Frequently Asked Questions
What is the fastest way to install LiteRT?
The Docker method is fastest for most users. Running ./docker_build/build_with_docker.sh from the repository root automatically handles dependency installation, configuration via configure.py, and compilation inside an Ubuntu 24.04 container, copying finished binaries back to your host bazel-bin/ directory.
How do I enable GPU or NPU support when building LiteRT?
For Bazel, pass --config=cuda or hardware-specific flags during the build command after running ./configure. For CMake, add -DLITERT_ENABLE_GPU=ON or -DLITERT_ENABLE_NPU=ON to your preset command (e.g., cmake --preset default -DLITERT_ENABLE_GPU=ON). These flags are processed by the build rules in litert/cc/BUILD and the root CMakeLists.txt to include delegate dispatchers.
Can I build LiteRT for Android using CMake?
Yes. Use the android-arm64 preset from CMakePresets.json after setting ANDROID_NDK_HOME to an NDK r27 or newer path. You must also specify -DTFLITE_HOST_TOOLS_DIR pointing to host-built FlatBuffers compiler binaries (flatc) to generate serialization code during the cross-compilation process.
Where does the configure script store my build settings?
The ./configure script (implemented in configure.py) writes environment-specific settings to .litert_configure.bazelrc in the repository root. This file contains variables like PYTHON_BIN_PATH and ANDROID_NDK_HOME that Bazel reads during subsequent builds to locate toolchains and dependencies defined in the WORKSPACE file.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →