Skip to content

Commit 47962eb

Browse files
committed
fix: migrate to LiteRT 1.4.0 for proper 16KB page size support
- Replace TensorFlow Lite 2.12.0 with LiteRT 1.4.0 - TFLite 2.12.0 (from 2022) lacks 16KB aligned native libraries - LiteRT 1.4.0 provides proper 16KB page alignment - Add verification script to check page size alignment - Bump version to 0.12.1
1 parent 44f0ed2 commit 47962eb

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
## 0.12.1 (October 28, 2025)
2+
* **CRITICAL FIX**: Properly implement Android 16KB page size support
3+
* Migrated from TensorFlow Lite 2.12.0 to Google AI Edge LiteRT 1.4.0
4+
* LiteRT provides native libraries with 16KB page alignment required by Google Play
5+
* Added verification script (scripts/verify_16kb.sh) to check page size alignment
6+
* Note: Version 0.12.0 claimed 16KB support but used TensorFlow Lite 2.12.0 (incompatible)
7+
18
## 0.12.0 (October 27, 2025)
2-
* Android 16KB page size support for Google Play 2025 compliance
9+
* Android 16KB page size support attempted (incomplete - fixed in 0.12.1)
310
* Updated Android Gradle Plugin to 8.6.1
411
* Updated Compile SDK to 36 (Android 15+)
512
* Modernized Gradle build system with plugins DSL

android/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ android {
6363

6464

6565
dependencies {
66-
def tflite_version = "2.12.0"
66+
def litert_version = "1.4.0"
6767

68-
implementation("org.tensorflow:tensorflow-lite:${tflite_version}")
69-
implementation("org.tensorflow:tensorflow-lite-gpu:${tflite_version}")
68+
implementation("com.google.ai.edge.litert:litert:${litert_version}")
69+
implementation("com.google.ai.edge.litert:litert-gpu:${litert_version}")
7070
}

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
name: tflite_flutter
1818
description: TensorFlow Lite Flutter plugin provides an easy, flexible, and fast Dart API to integrate TFLite models in flutter apps across mobile and desktop platforms.
19-
version: 0.12.0
19+
version: 0.12.1
2020
homepage: https://github.com/tensorflow/flutter-tflite
2121

2222
environment:

scripts/verify_16kb.sh

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#!/bin/bash
2+
3+
# Script to verify 16KB page size alignment for Android native libraries
4+
# Usage: ./verify_16kb.sh <path_to_apk_or_aab>
5+
6+
set -e
7+
8+
if [ $# -eq 0 ]; then
9+
echo "Usage: $0 <path_to_apk_or_aab>"
10+
echo "Example: $0 app-release.apk"
11+
exit 1
12+
fi
13+
14+
APK_PATH="$1"
15+
TEMP_DIR=$(mktemp -d)
16+
17+
echo "=========================================="
18+
echo "16KB Page Size Verification"
19+
echo "=========================================="
20+
echo "File: $APK_PATH"
21+
echo ""
22+
23+
# Extract the APK/AAB
24+
echo "Extracting archive..."
25+
unzip -q "$APK_PATH" -d "$TEMP_DIR"
26+
27+
# Find all .so files
28+
SO_FILES=$(find "$TEMP_DIR" -name "*.so" -type f)
29+
30+
if [ -z "$SO_FILES" ]; then
31+
echo "❌ No native libraries (.so files) found in the archive"
32+
rm -rf "$TEMP_DIR"
33+
exit 1
34+
fi
35+
36+
echo "Found native libraries:"
37+
echo "$SO_FILES" | sed 's|.*/||'
38+
echo ""
39+
40+
ALL_ALIGNED=true
41+
42+
# Check each .so file
43+
for SO_FILE in $SO_FILES; do
44+
SO_NAME=$(basename "$SO_FILE")
45+
ARCH=$(dirname "$SO_FILE" | xargs basename)
46+
47+
# Only check arm64-v8a and x86_64 architectures (required for 16KB)
48+
if [[ "$ARCH" == "arm64-v8a" ]] || [[ "$ARCH" == "x86_64" ]]; then
49+
echo "Checking: $ARCH/$SO_NAME"
50+
51+
# Check if readelf is available
52+
if ! command -v readelf &> /dev/null; then
53+
echo " ⚠️ readelf not found. Install binutils or use Android NDK's llvm-readelf"
54+
echo " Skipping detailed alignment check"
55+
continue
56+
fi
57+
58+
# Get LOAD segment alignments
59+
ALIGNMENTS=$(readelf -l "$SO_FILE" 2>/dev/null | grep LOAD | awk '{print $NF}')
60+
61+
MIN_ALIGNMENT=16384 # 2^14 = 16KB
62+
ALIGNED=true
63+
64+
for ALIGN in $ALIGNMENTS; do
65+
# Convert hex alignment (e.g., 2**14) to decimal
66+
if [[ "$ALIGN" =~ 2\*\*([0-9]+) ]]; then
67+
POWER="${BASH_REMATCH[1]}"
68+
ALIGN_VALUE=$((2**POWER))
69+
70+
if [ "$ALIGN_VALUE" -lt "$MIN_ALIGNMENT" ]; then
71+
echo " ❌ UNALIGNED: segment alignment 2**$POWER ($ALIGN_VALUE bytes) < 16KB"
72+
ALIGNED=false
73+
ALL_ALIGNED=false
74+
fi
75+
fi
76+
done
77+
78+
if [ "$ALIGNED" = true ]; then
79+
echo " ✅ ALIGNED: All segments meet 16KB requirement"
80+
fi
81+
echo ""
82+
fi
83+
done
84+
85+
# Cleanup
86+
rm -rf "$TEMP_DIR"
87+
88+
echo "=========================================="
89+
if [ "$ALL_ALIGNED" = true ]; then
90+
echo "✅ SUCCESS: All native libraries are 16KB aligned"
91+
echo "=========================================="
92+
exit 0
93+
else
94+
echo "❌ FAILURE: Some libraries are NOT 16KB aligned"
95+
echo "=========================================="
96+
echo ""
97+
echo "Recommended actions:"
98+
echo "1. Ensure you're using LiteRT 1.4.0+ or TensorFlow Lite 2.16.1+"
99+
echo "2. Verify AGP version is 8.5.1 or higher"
100+
echo "3. Check that NDK version is r27 or higher (if compiling native code)"
101+
echo "4. Rebuild your app after updating dependencies"
102+
exit 1
103+
fi

0 commit comments

Comments
 (0)