Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
1568b7f
Add Android 16KB page size support for ONNX Runtime Extensions
ssk18 Nov 11, 2025
280ffab
Adds ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES CMake option (default: ON) to
ssk18 Nov 11, 2025
88a80d2
Add documentation and CI for Android 16KB page size support
ssk18 Nov 11, 2025
8e8698d
Remove redundant target_link_options for 16KB page size
ssk18 Nov 12, 2025
addf59e
Merge branch 'main' into enable-16KB-for-android
ssk18 Nov 12, 2025
d21e703
Remove branch-specific push trigger from Android 16KB workflow
ssk18 Nov 12, 2025
51b1a75
Removed ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES option, always enable 16K…
ssk18 Nov 12, 2025
cf22e8f
added add_link_options() for 16KB page size flag
ssk18 Nov 12, 2025
51c9a1e
Updated Readme file
ssk18 Nov 12, 2025
10b411a
Updated workflow and verification script to remove obsolete option re…
ssk18 Nov 12, 2025
f378a3a
Updated NDK requirement comment to avoid version-specific references …
ssk18 Nov 13, 2025
73dd655
Updated JDK to 17
ssk18 Nov 13, 2025
5253244
Apply suggestion from @edgchen1
ssk18 Nov 13, 2025
413fa53
Added missing unordered_map include in tokenizer_common.h
ssk18 Nov 14, 2025
ef29598
Merge remote-tracking branch 'origin/enable-16KB-for-android' into en…
ssk18 Nov 14, 2025
41a1f98
Added workflow to only verify libortextensions and libonnxruntime_ex…
ssk18 Nov 15, 2025
b665df4
Merge branch 'main' into enable-16KB-for-android
ssk18 Nov 15, 2025
9b31d4d
Merge branch 'main' into enable-16KB-for-android
edgchen1 Nov 20, 2025
96a7194
Merge branch 'main' into enable-16KB-for-android
ssk18 Dec 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions .github/workflows/android-16kb-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
name: Android 16KB Page Size Verification
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sayanshaw24 is it ok to add a new workflow for this check? or would it be preferable to add it to the existing CI build pipeline?


on:
pull_request:
paths:
- 'CMakeLists.txt'
- 'cmake/**'
- 'java/**'
- 'tools/build.py'
- '.github/workflows/android-16kb-check.yml'
push:
branches:
- 'enable-16KB-for-android' # Your branch name

jobs:
verify-android-16kb-alignment:
name: Build & Verify 16KB Page Alignment (arm64-v8a)
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Set up JDK 11
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '11'

- name: Setup Android NDK
uses: nttld/setup-ndk@v1
id: setup-ndk
with:
ndk-version: r25c
add-to-path: false

- name: Set up Android SDK
uses: android-actions/setup-android@v3

- name: Build Android arm64-v8a with 16KB support
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
set -e

# Use the project's build script
python tools/build.py \
--android \
--android_abi=arm64-v8a \
--android_api=27 \
--android_home=$ANDROID_HOME \
--android_ndk_path=$ANDROID_NDK_HOME \
--config=Release \
--parallel \
--build \
--cmake_extra_defines ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON

- name: Verify 16KB page alignment
env:
ANDROID_NDK_HOME: ${{ steps.setup-ndk.outputs.ndk-path }}
run: |
set -e

echo "=== Verifying 16KB page size alignment ==="

# Find built libraries
LIBS=$(find build/Android -name "*.so" -type f)

if [ -z "$LIBS" ]; then
echo "ERROR: No .so files found in build output"
find build -type f -name "*.so" || true
exit 1
fi

# Use llvm-readelf from NDK
READELF="$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-readelf"

if [ ! -f "$READELF" ]; then
echo "ERROR: llvm-readelf not found at $READELF"
exit 1
fi

echo "Found libraries:"
echo "$LIBS"
echo ""

FAILED=0
for LIB in $LIBS; do
echo "Checking: $(basename $LIB)"
echo "Full path: $LIB"

# Display LOAD segments
$READELF -l "$LIB" | grep -A 1 "LOAD" || true

# Check for 16KB alignment (0x4000)
if $READELF -l "$LIB" | grep -q "0x4000"; then
echo "PASS: Found 16KB alignment (0x4000) in $(basename $LIB)"
else
echo "FAIL: Did not find 16KB alignment (0x4000) in $(basename $LIB)"
echo "Full segment details:"
$READELF -l "$LIB"
FAILED=1
fi
echo "---"
done

if [ $FAILED -ne 0 ]; then
echo ""
echo "ERROR: One or more libraries do not have 16KB page alignment"
exit 1
fi

echo ""
echo "SUCCESS: All libraries have correct 16KB page alignment"

- name: Upload build artifacts
if: always()
uses: actions/upload-artifact@v4
with:
name: android-arm64-libraries
path: build/Android/**/lib/*.so
retention-days: 7
18 changes: 18 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,24 @@ if(OCOS_BUILD_ANDROID)
endif()

set(OCOS_BUILD_JAVA ON CACHE INTERNAL "")

# Add 16KB page size compatibility for Android 15+ devices
# See: https://developer.android.com/guide/practices/page-sizes
# This flag ensures binaries work on both 4KB and 16KB page size systems
option(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES "Enable 16KB page size support for Android" ON)

if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
# Android NDK uses Clang + lld which supports this flag
if(CMAKE_C_COMPILER_ID MATCHES "Clang|GNU")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
message(STATUS "Android build: 16KB page size support enabled")
else()
message(WARNING "Compiler ${CMAKE_C_COMPILER_ID} may not support -Wl,-z,max-page-size. Skipping.")
endif()
else()
message(WARNING "Android build: 16KB page size support disabled (not recommended for production)")
endif()
endif()

# Build the libraries with -fPIC
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ Introduction: ONNXRuntime-Extensions is a C/C++ library that extends the capabil
## Quickstart
The library can be utilized as either a C/C++ library or other advance language packages like Python, Java, C#, etc. To build it as a shared library, you can use the `build.bat` or `build.sh` scripts located in the root folder. The CMake build definition is available in the `CMakeLists.txt` file and can be modified by appending options to `build.bat` or `build.sh`, such as `build.bat -DOCOS_BUILD_SHARED_LIB=OFF`. For more details, please refer to the [C API documentation](./docs/c_api.md).

### Android 16KB Page Size Support
Android builds automatically enable 16KB page size compatibility to support Android 15+ devices. The linker flag `-Wl,-z,max-page-size=16384` sets the maximum page alignment, ensuring binaries work on both traditional 4KB and newer 16KB page size systems. This is controlled by the `ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES` CMake option (default: ON) and applies safely to all Android ABIs including 32-bit architectures. The flag only sets a maximum alignment constraint and does not negatively impact devices using 4KB pages.

### **Python installation**
```bash
pip install onnxruntime-extensions
Expand Down
10 changes: 10 additions & 0 deletions java/build-android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ android {
versionName = project.version

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}

externalNativeBuild {
cmake {
arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
}
}
}

android {
Expand Down
14 changes: 12 additions & 2 deletions java/src/test/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

ndk {
abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
}

externalNativeBuild {
cmake {
arguments "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON"
}
}
}

buildTypes {
Expand All @@ -37,9 +47,9 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.microsoft.onnxruntime:onnxruntime-android:latest.release'
if (ortExtensionsAarLocalPath != null) {
implementation files(ortExtensionsAarLocalPath)
implementation files(ortExtensionsAarLocalPath)
} else {
implementation 'com.microsoft.onnxruntime:onnxruntime-extensions-android:latest.release'
implementation 'com.microsoft.onnxruntime:onnxruntime-extensions-android:latest.release'
}
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
1 change: 1 addition & 0 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def _generate_build_tree(
+ str((args.android_ndk_path / "build" / "cmake" / "android.toolchain.cmake").resolve(strict=True)),
f"-DANDROID_PLATFORM=android-{args.android_api}",
f"-DANDROID_ABI={args.android_abi}",
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
]

if is_macOS() and not args.android:
Expand Down