From 6e892a95b4ee1234add6b33d0172858da900a059 Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Thu, 28 Jul 2022 11:01:04 -0700 Subject: [PATCH] Use specific Android NDK version in CI builds. (#12350) Current builds use a NDK version that happens to be on the build machine. The build machine environment may change in ways that are outside of our control. This change installs a specific version of NDK (the current LTS version 25.0.8775105) and uses it. --- ...ndroid-x86_64-crosscompile-ci-pipeline.yml | 27 ++++++++++------- .../templates/android-java-api-aar-test.yml | 2 ++ .../templates/android-java-api-aar.yml | 2 ++ .../templates/use-android-ndk.yml | 30 +++++++++++++++++++ 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 tools/ci_build/github/azure-pipelines/templates/use-android-ndk.yml diff --git a/tools/ci_build/github/azure-pipelines/android-x86_64-crosscompile-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/android-x86_64-crosscompile-ci-pipeline.yml index 40f95fd057..56680322da 100644 --- a/tools/ci_build/github/azure-pipelines/android-x86_64-crosscompile-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/android-x86_64-crosscompile-ci-pipeline.yml @@ -23,6 +23,8 @@ jobs: - script: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build displayName: Install coreutils and ninja + - template: "templates/use-android-ndk.yml" + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(pwd) displayName: Setup gradle wrapper to use gradle 6.8.3 @@ -35,12 +37,8 @@ jobs: displayName: Build Host Protoc - script: | - export ANDROID_SDK_ROOT=/usr/local/lib/android/sdk - export ANDROID_HOME=/usr/local/lib/android/sdk - export ANDROID_NDK_HOME=/usr/local/lib/android/sdk/ndk-bundle - export ANDROID_NDK_ROOT=/usr/local/lib/android/sdk/ndk-bundle env | grep ANDROID - displayName: Set Android ENVs + displayName: View Android ENVs # Start switching to jdk 11 after the Android Emulator is started # since Android SDK manager requires java 8 @@ -116,6 +114,13 @@ jobs: artifact: 'CPUBuildOutput' path: $(Build.SourcesDirectory) + - task: UsePythonVersion@0 + displayName: Use Python $(pythonVersion) + inputs: + versionSpec: $(pythonVersion) + + - template: "templates/use-android-ndk.yml" + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(pwd) displayName: Setup gradle wrapper to use gradle 6.8.3 @@ -173,6 +178,8 @@ jobs: - script: sudo apt-get update -y && sudo apt-get install -y coreutils ninja-build displayName: Install coreutils and ninja + - template: "templates/use-android-ndk.yml" + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(pwd) displayName: Setup gradle wrapper to use gradle 6.8.3 @@ -185,12 +192,8 @@ jobs: displayName: Build Host Protoc - script: | - export ANDROID_SDK_ROOT=/usr/local/lib/android/sdk - export ANDROID_HOME=/usr/local/lib/android/sdk - export ANDROID_NDK_HOME=/usr/local/lib/android/sdk/ndk-bundle - export ANDROID_NDK_ROOT=/usr/local/lib/android/sdk/ndk-bundle env | grep ANDROID - displayName: set Android ENVs + displayName: View Android ENVs # Start switching to jdk 11 after the Android Emulator is started since Android SDK manager requires java 8 - task: JavaToolInstaller@0 @@ -272,6 +275,8 @@ jobs: inputs: versionSpec: $(pythonVersion) + - template: "templates/use-android-ndk.yml" + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(pwd) displayName: Setup gradle wrapper to use gradle 6.8.3 @@ -350,6 +355,8 @@ jobs: inputs: versionSpec: $(pythonVersion) + - template: "templates/use-android-ndk.yml" + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(pwd) displayName: Setup gradle wrapper to use gradle 6.8.3 diff --git a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml index 8dbee4491d..5c64f4b619 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar-test.yml @@ -37,6 +37,8 @@ jobs: artifactName: '${{parameters.artifactName}}' targetPath: '$(Build.BinariesDirectory)/final-android-aar' + - template: use-android-ndk.yml + - script: /bin/bash tools/ci_build/github/android/setup_gradle_wrapper.sh $(Build.SourcesDirectory) displayName: Setup gradle wrapper to use gradle 6.8.3 diff --git a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml index 8a6a2959e2..2be0f48bb2 100644 --- a/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml +++ b/tools/ci_build/github/azure-pipelines/templates/android-java-api-aar.yml @@ -72,6 +72,8 @@ jobs: DockerBuildArgs: "--build-arg BUILD_UID=$( id -u )" Repository: onnxruntimecpubuild + - template: use-android-ndk.yml + - task: CmdLine@2 displayName: Build Android AAR Packages inputs: diff --git a/tools/ci_build/github/azure-pipelines/templates/use-android-ndk.yml b/tools/ci_build/github/azure-pipelines/templates/use-android-ndk.yml new file mode 100644 index 0000000000..de188e08be --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/templates/use-android-ndk.yml @@ -0,0 +1,30 @@ +# Installs the Android NDK and sets environment variables ANDROID_NDK_HOME and ANDROID_NDK_ROOT to refer to it. + + parameters: + - name: AndroidNdkVersion + type: string + default: "25.0.8775105" # LTS version + + steps: + - bash: | + set -e + + "${ANDROID_SDK_ROOT}/cmdline-tools/latest/bin/sdkmanager" --install "ndk;${{ parameters.AndroidNdkVersion }}" + + NDK_PATH="${ANDROID_SDK_ROOT}/ndk/${{ parameters.AndroidNdkVersion }}" + if [[ ! -d "${NDK_PATH}" ]]; then + echo "NDK directory is not in expected location: ${NDK_PATH}" + exit 1 + fi + + set_var() { + local VAR_NAME=${1:?} + local VAR_VALUE=${2:?} + echo "##vso[task.setvariable variable=${VAR_NAME}]${VAR_VALUE}" + echo "${VAR_NAME}: ${VAR_VALUE}" + } + + set_var "ANDROID_NDK_HOME" "${NDK_PATH}" + set_var "ANDROID_NDK_ROOT" "${NDK_PATH}" + + displayName: Use Android NDK ${{ parameters.AndroidNdkVersion }}