Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
123 changes: 123 additions & 0 deletions .github/workflows/android-16kb-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
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'

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 \
--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 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
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ 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 NDK r23+.
add_link_options(-Wl,-z,max-page-size=16384)
message(STATUS "Android build: 16KB page size support enabled")
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
Loading