Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 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
ddbd151
Merge branch 'main' into enable-16KB-for-android
ssk18 Feb 19, 2026
ea3b171
Merge branch 'main' into enable-16KB-for-android
sayanshaw24 Feb 20, 2026
a087d1c
Update CMakeLists.txt
ssk18 Feb 22, 2026
ab09f98
Update .github/workflows/android-16kb-check.yml
ssk18 Feb 22, 2026
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
124 changes: 124 additions & 0 deletions .github/workflows/android-16kb-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Android 16KB Page Size Verification

on:
pull_request:
paths:
- 'CMakeLists.txt'
- 'cmake/**'
- 'java/**'
- 'tools/build.py'
- '.github/workflows/android-16kb-check.yml'

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 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'

- 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 \
--update \
--parallel \
--build

- 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 android built libraries
LIBS=$(find build/Android/Release/lib -name "libortextensions.so" -o -name "libonnxruntime_extensions4j_jni.so")
Comment on lines +68 to +69
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The library search path assumes a specific directory structure build/Android/Release/lib, but depending on the build configuration and whether multiple ABIs are being built, the actual library paths might be different. Consider making the search more flexible by using a recursive search from build/Android or by using the actual build configuration directory. For example: find build/Android -name "*.so" -path "*/lib/*" would be more robust if the directory structure varies.

Suggested change
# Find android built libraries
LIBS=$(find build/Android/Release/lib -name "libortextensions.so" -o -name "libonnxruntime_extensions4j_jni.so")
# Find android built libraries (search recursively under build/Android, limited to lib directories)
LIBS=$(find build/Android -type f -path "*/lib/*" \( -name "libortextensions.so" -o -name "libonnxruntime_extensions4j_jni.so" \))

Copilot uses AI. Check for mistakes.

if [ -z "$LIBS" ]; then
echo "ERROR: Android built libraries not found"
find build/Android -name "*.so" -type f || 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) in the Align field of LOAD segments
if $READELF -l "$LIB" | grep "LOAD" | awk '{print $NF}' | 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
12 changes: 12 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,18 @@ 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.
# Requires Android NDK r23 or newer because -Wl,-z,max-page-size=16384 was
# introduced in NDK r23. Ensure all build tooling (CMake, Gradle, CI) uses
# an NDK >= r23.
if(DEFINED ANDROID_NDK_MAJOR AND ANDROID_NDK_MAJOR LESS 23)
message(FATAL_ERROR "Android NDK r23 or newer is required to build with 16KB page size support. Detected ANDROID_NDK_MAJOR=${ANDROID_NDK_MAJOR}")
endif()
add_link_options(-Wl,-z,max-page-size=16384)
message(STATUS "Android build: 16KB page size support enabled")
Comment on lines +231 to +232
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The PR description mentions changes to cmake/ext_java.cmake to "Configure JNI library with 16KB page alignment," but this file is not included in the pull request diff. Please verify if:

  1. This change was intended but accidentally omitted from the PR
  2. The change is no longer necessary (in which case the PR description should be updated)
  3. The PR description is incorrect

Given that the linker flag in CMakeLists.txt uses add_link_options() which applies globally to all targets built under the Android configuration, it should affect the JNI library. However, if there are specific configurations needed in ext_java.cmake, they should be included in this PR.

Copilot uses AI. Check for mistakes.
Comment on lines +231 to +232
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The PR description states that tools/build.py should have changes to "Enable ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES flag," but:

  1. This file is not included in the pull request diff
  2. A search of the file shows no references to ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES

The ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES flag is a Gradle property that can be set in gradle.properties or as a CMake argument to signal Android build systems that the app supports flexible page sizes. Without this flag set, the changes in this PR may not provide the full intended compatibility. Please either:

  1. Add the missing changes to tools/build.py if they're needed
  2. Update the PR description if this change is no longer necessary
  3. Clarify where this flag should be set (e.g., in gradle configuration files)

Copilot uses AI. Check for mistakes.
endif()

# Build the libraries with -fPIC
Expand Down
4 changes: 4 additions & 0 deletions java/build-android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ android {
versionName = project.version

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

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

android {
Expand Down
8 changes: 6 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,10 @@ android {
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

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

buildTypes {
Expand All @@ -37,9 +41,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 operators/tokenizer/tokenizer_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <string>
#include <string_view>
#include <unordered_map>

#include "ortx_tokenizer.h"
#include "ext_status.h"
Expand Down