Issue:
We’re using libtensorflowlite_jni.so (from org.tensorflow:tensorflow-lite:2.17.0) in an Android project.
We’re targeting SDK 35+ on Android devices that require 16 KB page size. But when inspecting the .so using readelf, the memory segments are aligned to 4 KB (0x1000), not 16 KB (0x4000). As a result, we get the error: Only 4 KB page compatible.
Question:
- Is there an officially supported build of
libtensorflowlite_jni.so that supports 16 KB page size?
- If not, is there a CMake or Bazel flag to compile TensorFlow Lite with 16 KB alignment for Android?
Info:
- TensorFlow Lite version: 2.17.0
- Target ABI: arm64-v8a
- Min SDK: 23
- NDK: r25+
What we tried:
- Downloaded AAR from Maven Central
- Used
readelf -l libtensorflowlite_jni.so to check LOAD alignment
Hi, @kevin_santoki
First of all Welcome to our Google AI Developers Forum, I apologize for the delay in my response The root cause of this issue is that TensorFlow Lite 2.17.0’s pre-built native libraries are compiled with 4KB page size alignment not the required 16KB alignment for Android 15+ devices. When inspecting the libtensorflowlite_jni.so file using readelf -l , the LOAD segments show an alignment of 0x1000 (4KB) instead of the required 0x4000 (16KB).
The officially recommended solution is migrating to LiteRT (formerly TensorFlow Lite) version 1.4.0 , which provides 16KB page size compatibility. code migration is minimal as LiteRT maintains the same API structure as TensorFlow Lite please refer this official documentation of Migrate to LiteRT from TensorFlow Lite
// Replace TensorFlow Lite dependencies with LiteRT
dependencies {
// Remove these:
// implementation 'org.tensorflow:tensorflow-lite:2.17.0'
// Add these:
implementation 'com.google.ai.edge.litert:litert:1.4.0'
implementation 'com.google.ai.edge.litert:litert-api:1.4.0'
implementation 'com.google.ai.edge.litert:litert-support:1.4.0'
implementation 'com.google.ai.edge.litert:litert-metadata:1.4.0'
}
If migration isn’t feasible, build TensorFlow Lite from source with 16KB alignment:
# Bazel build command with 16KB alignment flag
bazel build -c opt --config=android_arm64 \
--repo_env=HERMETIC_PYTHON_VERSION=3.12 \
//tensorflow/lite/java:tensorflow-lite.aar \
--linkopt='-Wl,-z,max-page-size=16384'
For custom builds ensure you have:
- Android NDK r28+ (automatically builds with 16KB alignment) [Ref]
- Android Gradle Plugin 8.5.1+
- Gradle 8.4+
- Target SDK 35+
- NDK r27 Configuration (if using older NDK)
Thank you for your cooperation and patience.