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.event_name == 'pull_request' && github.ref || github.sha }} cancel-in-progress: true permissions: contents: read packages: write attestations: write id-token: write jobs: AndroidBinarySizeCheckJob_MinimalBaseline: runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU", "JobId=AndroidBinarySizeCheckJob_MinimalBaseline-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" ] timeout-minutes: 120 env: CCACHE_DIR: ~/.cache/ccache # explicitly set to prevent any fallback to `~/.ccache` steps: - name: Checkout repository uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 with: submodules: false - name: Setup Android NDK uses: ./.github/actions/setup-android-ndk with: ndk-version: 28.0.13004108 - name: Get Docker Image using Action uses: microsoft/onnxruntime-github-actions/build-docker-image@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12 id: build_docker_image_step with: dockerfile: ${{ github.workspace }}/tools/ci_build/github/linux/docker/inference/x86_64/default/cpu/Dockerfile image-name: ghcr.io/microsoft/onnxruntime/onnxruntimecpubuildcix64 push: true azure-container-registry-name: onnxruntimebuildcache env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Set variables from config file id: set_vars run: | import json, os config_file_path = "tools/ci_build/github/linux/ort_minimal/build_check_binsize_config/android_minimal_baseline.config" with open(config_file_path, mode="r") as config_file: config = json.load(config_file) def set_var(name, value): print(f"Setting variable: {name} = '{value}'") # Use GITHUB_ENV for setting environment variables with open(os.environ['GITHUB_ENV'], 'a') as f: f.write(f"{name}={value}\n") set_var("BuildConfigType", config["type"]) set_var("BuildConfigOs", config["os"]) shell: python working-directory: ${{ github.workspace }} # FUTURE WORK: ccache, vcpkg cache - name: 1a. Build onnxruntime run: | set -e -x BINARY_SIZE_THRESHOLD_ARGS="" BINARY_SIZE_THRESHOLD_IN_BYTES=1607680 echo "Binary size threshold in bytes: ${BINARY_SIZE_THRESHOLD_IN_BYTES}" BINARY_SIZE_THRESHOLD_ARGS="--threshold_size_in_bytes ${BINARY_SIZE_THRESHOLD_IN_BYTES}" # Ensure ANDROID_NDK_HOME is available and get its real path if [ -z "$ANDROID_NDK_HOME" ]; then echo "ANDROID_NDK_HOME is not set." exit 1 fi NDK_HOME_REALPATH=$(realpath $ANDROID_NDK_HOME) # Ensure ANDROID_HOME is available if [ -z "$ANDROID_HOME" ]; then echo "ANDROID_HOME is not set. Using default /usr/local/lib/android/sdk" export ANDROID_HOME=/usr/local/lib/android/sdk fi docker run -e SYSTEM_COLLECTIONURI --rm \ --volume ${{ github.workspace }}:/onnxruntime_src \ --volume ${{ runner.temp }}:/build \ --volume $ANDROID_HOME:/android_home \ --volume $NDK_HOME_REALPATH:/ndk_home \ -w /onnxruntime_src \ -e ALLOW_RELEASED_ONNX_OPSET_ONLY=1 \ -e NIGHTLY_BUILD=1 \ -e BUILD_BUILDNUMBER=${{ github.run_number }} \ -e BUILD_SOURCEVERSION=${{ github.sha }} \ -e BUILD_ID=${{ github.run_id }} \ -e BUILD_REASON=${{ github.event_name }} \ -e BUILD_BRANCH=${{ github.ref }} \ -e RUNNER_TEMP=/build \ ${{ steps.build_docker_image_step.outputs.full-image-name }} \ bash -c "python3 -m pip install -r /onnxruntime_src/tools/ci_build/requirements/pybind/requirements.txt && \ python3 tools/ci_build/github/linux/ort_minimal/build_ort_and_check_binary_size.py \ --build_dir /build/1a \ ${BINARY_SIZE_THRESHOLD_ARGS} \ tools/ci_build/github/linux/ort_minimal/build_check_binsize_config/android_minimal_baseline.config" shell: bash android_nnapi_ep: runs-on: [ "self-hosted", "1ES.Pool=onnxruntime-github-Ubuntu2204-AMD-CPU", "JobId=android_nnapi_ep-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" ] timeout-minutes: 120 env: CCACHE_DIR: ~/.cache/ccache # explicitly set to prevent any fallback to `~/.ccache` steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Use jdk 17 uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 with: distribution: 'temurin' java-version: '17' architecture: x64 - name: Get vcpkg tool info id: vcpkg-tool-info uses: ./.github/actions/get-vcpkg-tool-info - uses: microsoft/onnxruntime-github-actions/setup-build-tools@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12 with: ccache-version: 4.13.1 ccache-hash: 626407a9b81dd86f8ec9867bff396b32dd1f00344f5b323526579a64f6d4104927f83e8d7a05ad9806fd78f4491e0adb4cff73388000a62050cb1b00766214ee vcpkg-version: ${{ steps.vcpkg-tool-info.outputs.release_tag }} vcpkg-hash: ${{ steps.vcpkg-tool-info.outputs.sha512 }} cmake-version: '3.31.6' cmake-hash: '42395e20b10a8e9ef3e33014f9a4eed08d46ab952e02d2c1bbc8f6133eca0d7719fb75680f9bbff6552f20fcd1b73d86860f7f39388d631f98fb6f622b37cf04' add-cmake-to-path: 'true' disable-terrapin: 'true' - name: Setup Android NDK uses: ./.github/actions/setup-android-ndk with: ndk-version: 28.0.13004108 - name: Test static telemetry package dependencies on Linux and Android shell: bash run: | test -n "$ANDROID_NDK_HOME" python3 tools/ci_build/test_telemetry_package.py -v - name: Setup CCache uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 with: # Fully qualify by workflow. `actions/cache` does not isolate by workflow, unlike ADO cache actions. key: ccache | android.yml | android_nnapi_ep path: ~/.cache/ccache - name: Setup VCPKG Cache uses: ./.github/actions/setup-vcpkg-cache with: key: android-nnapi-ep - name: CCache reset stats run: ccache --zero-stats shell: bash - 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_cache --use_vcpkg --use_vcpkg_ms_internal_asset_cache --use_nnapi --build_shared_lib --cmake_generator=Ninja --build_java --update --build --test 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: CCache stats run: ccache --show-stats -vv 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", "JobId=android_cpu_ep-${{ github.run_id }}-${{ github.run_number }}-${{ github.run_attempt }}" ] timeout-minutes: 120 env: CCACHE_DIR: ~/.cache/ccache # explicitly set to prevent any fallback to `~/.ccache` steps: - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0 - name: Use jdk 17 uses: actions/setup-java@de7274f081f381c8f8158605e0321c36c376e2e6 # v6.0.1 with: distribution: 'temurin' java-version: '17' architecture: x64 - name: Get vcpkg tool info id: vcpkg-tool-info uses: ./.github/actions/get-vcpkg-tool-info - uses: microsoft/onnxruntime-github-actions/setup-build-tools@8bad63a3c05d448311dfa8e5f531171c97471aa1 # v0.0.12 with: ccache-version: 4.13.1 ccache-hash: 626407a9b81dd86f8ec9867bff396b32dd1f00344f5b323526579a64f6d4104927f83e8d7a05ad9806fd78f4491e0adb4cff73388000a62050cb1b00766214ee vcpkg-version: ${{ steps.vcpkg-tool-info.outputs.release_tag }} vcpkg-hash: ${{ steps.vcpkg-tool-info.outputs.sha512 }} cmake-version: '3.31.6' cmake-hash: '42395e20b10a8e9ef3e33014f9a4eed08d46ab952e02d2c1bbc8f6133eca0d7719fb75680f9bbff6552f20fcd1b73d86860f7f39388d631f98fb6f622b37cf04' add-cmake-to-path: 'true' disable-terrapin: 'true' - name: Setup Android NDK uses: ./.github/actions/setup-android-ndk with: ndk-version: 28.0.13004108 - name: Setup CCache uses: actions/cache@caa296126883cff596d87d8935842f9db880ef25 # v5.1.0 with: # Fully qualify by workflow. `actions/cache` does not isolate by workflow, unlike ADO cache actions. key: ccache | android.yml | android_cpu_ep path: ~/.cache/ccache - name: Setup VCPKG Cache uses: ./.github/actions/setup-vcpkg-cache with: key: android-cpu-ep - name: CCache reset stats run: ccache --zero-stats shell: bash - 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_cache --use_vcpkg --use_vcpkg_ms_internal_asset_cache --cmake_generator=Ninja --build_java --update --build --test shell: bash - name: CCache stats run: ccache --show-stats -vv 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