Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
98 changes: 98 additions & 0 deletions .github/actions/setup-android-ndk/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# .github/actions/setup-android-ndk/action.yml
name: 'Setup Android NDK'
description: 'Installs and configures a specific version of the Android NDK'
inputs:
ndk-version:
description: 'The version of the Android NDK to install (e.g., 27.2.12479018)'
required: true
default: '27.2.12479018'
android-sdk-root:
description: 'The root directory of the Android SDK'
required: true
default: '/usr/local/lib/android/sdk'

runs:
using: "composite" # Use a composite action for multiple shell commands
steps:
- name: Install coreutils and ninja
shell: bash
run: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build

- name: Install Android NDK
shell: bash
run: |
set -e
"${{ inputs.android-sdk-root }}/cmdline-tools/latest/bin/sdkmanager" --install "ndk;${{ inputs.ndk-version }}"

NDK_PATH="${{ inputs.android-sdk-root }}/ndk/${{ inputs.ndk-version }}"
if [[ ! -d "${NDK_PATH}" ]]; then
echo "NDK directory is not in expected location: ${NDK_PATH}"
exit 1
fi

# Use standard environment variable setting in bash and add to GITHUB_ENV
echo "ANDROID_NDK_HOME=${NDK_PATH}" >> $GITHUB_ENV
echo "ANDROID_NDK_ROOT=${NDK_PATH}" >> $GITHUB_ENV
echo "ANDROID_NDK_HOME: ${NDK_PATH}"
echo "ANDROID_NDK_ROOT: ${NDK_PATH}"

- name: Check if emulator are installed and add to PATH
shell: bash
run: |
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/emulator:"* ]]; then
echo "${ANDROID_SDK_ROOT}/emulator is in PATH"
else
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "emulator"
echo "${ANDROID_SDK_ROOT}/emulator" >> $GITHUB_PATH
fi

- name: Check if platform tools are installed and add to PATH
shell: bash
run: |
if [[ ":$PATH:" == *":${ANDROID_SDK_ROOT}/platform-tools:"* ]]; then
echo "${ANDROID_SDK_ROOT}/platform-tools is in PATH"
else
${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager --install "platform-tools"
echo "${ANDROID_SDK_ROOT}/platform-tools" >> $GITHUB_PATH
fi
ls -R "${ANDROID_SDK_ROOT}/platform-tools"

- name: Create Android Emulator
shell: bash
env:
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
run: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root "${ANDROID_SDK_ROOT}" \
--create-avd --system-image "system-images;android-31;default;x86_64"

- name: List Android AVDs
shell: bash
env:
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
run: |
"${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/avdmanager" list avd

- name: Check emulator.pid does not exist
shell: bash
run: |
if test -f ./emulator.pid; then
echo "Emulator PID file was not expected to exist but does and has pid: `cat ./emulator.pid`"
exit 1
fi

- name: Start Android Emulator
shell: bash
env:
ANDROID_AVD_HOME: ${{ runner.temp }}/android-avd
run: |
set -e -x
python3 tools/python/run_android_emulator.py \
--android-sdk-root "${ANDROID_SDK_ROOT}" \
--start --emulator-extra-args="-partition-size 2047" \
--emulator-pid-file ./emulator.pid
echo "Emulator PID: `cat ./emulator.pid`"

- name: View Android ENVs
shell: bash
run: env | grep ANDROID
147 changes: 147 additions & 0 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
name: Android CI
# This workflow is used to build and test on Android Emulator on Linux

on:
push:
branches:
- main
- rel-*
pull_request:
branches:
- main
- rel-*
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name == 'workflow_dispatch' }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
android_nnapi_ep:
runs-on: ["self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU"]
steps:
- uses: actions/checkout@v4

- name: Use jdk 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
architecture: x64

- name: Setup Android NDK
uses: ./.github/actions/setup-android-ndk
with:
ndk-version: 27.2.12479018

- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: NNAPI EP, Build, Test on Android Emulator
run: >-
python3 tools/ci_build/build.py
--enable_lto
--android
--build_dir build_nnapi
--android_sdk_path "$ANDROID_HOME"
--android_ndk_path "$ANDROID_NDK_HOME"
--android_abi=x86_64
--android_api=29
--skip_submodule_sync
--parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache
--use_nnapi
--build_shared_lib
--cmake_generator=Ninja
--build_java
shell: bash


- name: Build Minimal ORT with NNAPI and run tests
run: tools/ci_build/github/linux/ort_minimal/nnapi_minimal_build_minimal_ort_and_run_tests.sh "$(pwd)"
shell: bash

- name: Install psutil for emulator shutdown by run_android_emulator.py
if: always()
run: python3 -m pip install psutil
shell: bash

- name: Stop Android Emulator
if: always()
run: |
env | grep ANDROID
if test -f ${{ github.workspace }}/emulator.pid; then
echo "Emulator PID:"`cat ${{ github.workspace }}/emulator.pid`
python3 tools/python/run_android_emulator.py \
--android-sdk-root "${ANDROID_SDK_ROOT}" \
--stop \
--emulator-pid-file ${{ github.workspace }}/emulator.pid
rm ${{ github.workspace }}/emulator.pid
else
echo "Emulator PID file was expected to exist but does not."
fi
shell: bash

android_cpu_ep:
name: Android CI Pipeline
runs-on: ["self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU"]
steps:
- uses: actions/checkout@v4

- name: Use jdk 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
architecture: x64

- name: Setup Android NDK
uses: ./.github/actions/setup-android-ndk
with:
ndk-version: 27.2.12479018

- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: CPU EP, Build and Test
run: >-
python3 tools/ci_build/build.py
--enable_lto
--android
--build_dir build
--android_sdk_path $ANDROID_HOME
--android_ndk_path $ANDROID_NDK_HOME
--android_abi=x86_64
--android_api=30
--skip_submodule_sync
--parallel --use_vcpkg --use_vcpkg_ms_internal_asset_cache
--cmake_generator=Ninja
--build_java
shell: bash

- name: Install psutil for emulator shutdown by run_android_emulator.py
if: always()
run: python3 -m pip install psutil
shell: bash

- name: Stop Android Emulator
if: always()
run: |
if test -f ${{ github.workspace }}/emulator.pid; then
echo "Emulator PID:"`cat ${{ github.workspace }}/emulator.pid`
python3 tools/python/run_android_emulator.py \
--android-sdk-root "${ANDROID_SDK_ROOT}" \
--stop \
--emulator-pid-file ${{ github.workspace }}/emulator.pid
rm ${{ github.workspace }}/emulator.pid
else
echo "Emulator PID file was expected to exist but does not."
fi
shell: bash
Loading
Loading