diff --git a/java/build-android.gradle b/java/build-android.gradle index bfbb6f4596..a96192bb8d 100644 --- a/java/build-android.gradle +++ b/java/build-android.gradle @@ -7,6 +7,8 @@ def headersDir = System.properties['headersDir'] def publishDir = System.properties['publishDir'] def minSdkVer = System.properties['minSdkVer'] def targetSdkVer = System.properties['targetSdkVer'] +def buildVariant = System.properties['buildVariant'] ?: "Full" +boolean isMobileBuild = (buildVariant == "Mobile") // Since Android requires a higher numbers indicating more recent versions // This function assume ORT version number will be in formart of A.B.C such as 1.7.0 @@ -24,7 +26,17 @@ project.buildDir = buildDir project.version = rootProject.file('../VERSION_NUMBER').text.trim() project.group = "com.microsoft.onnxruntime" -def mavenArtifactId = project.name + '-mobile' +def mavenArtifactId = isMobileBuild ? project.name + '-mobile' : project.name + '-android' +def mobileDescription = 'The ONNX Runtime Mobile package is a size optimized inference library for executing ONNX ' + + '(Open Neural Network Exchange) models on Android. This package is built from the open source inference engine ' + + 'but with reduced disk footprint targeting mobile platforms. To minimize binary size this library supports a ' + + 'reduced set of operators and types aligned to typical mobile applications. The ONNX model must be converted to ' + + 'ORT format in order to use it with this package. ' + + 'See https://onnxruntime.ai/docs/reference/ort-model-format.html for more details.' +def defaultDescription = 'ONNX Runtime is a performance-focused inference engine for ONNX (Open Neural Network ' + + 'Exchange) models. This package contains the Android (aar) build of ONNX Runtime. It includes support for all ' + + 'types and operators, for ONNX format models. All standard ONNX models can be executed with this package. ' + + 'As such the binary size and memory usage will be larger than the onnxruntime-mobile package.' buildscript { repositories { @@ -126,9 +138,7 @@ publishing { pom { name = 'onnx-runtime' - description = 'ONNX Runtime Mobile package is a size optimized inference library for executing ' + - 'ONNX (Open Neural Network Exchange) models. This package is built from the open source ' + - 'inference engine targeting reduced disk footprint for mobile platforms.' + description = isMobileBuild ? mobileDescription : defaultDescription url = 'https://microsoft.github.io/onnxruntime/' licenses { license { diff --git a/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh b/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh index 83a4813e84..c52eb0217e 100755 --- a/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh +++ b/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh @@ -28,7 +28,6 @@ else fi # Copy the built artifacts to give folder for publishing -PACKAGE_NAME=onnxruntime-mobile BASE_PATH=/build/aar_out/${BUILD_CONFIG}/com/microsoft/onnxruntime/${PACKAGE_NAME}/${ORT_VERSION} cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-javadoc.jar /home/onnxruntimedev/.artifacts cp ${BASE_PATH}/${PACKAGE_NAME}-${ORT_VERSION}-sources.jar /home/onnxruntimedev/.artifacts diff --git a/tools/ci_build/github/android/build_aar_package.py b/tools/ci_build/github/android/build_aar_package.py index 948942a914..44580555a5 100644 --- a/tools/ci_build/github/android/build_aar_package.py +++ b/tools/ci_build/github/android/build_aar_package.py @@ -14,6 +14,7 @@ SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) REPO_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, "..", "..", "..", "..")) BUILD_PY = os.path.join(REPO_DIR, "tools", "ci_build", "build.py") JAVA_ROOT = os.path.join(REPO_DIR, "java") +DEFAULT_BUILD_VARIANT = "Full" sys.path.insert(0, os.path.join(REPO_DIR, "tools", "python")) from util import is_windows # noqa: E402 @@ -70,6 +71,8 @@ def _parse_build_settings(args): )) build_settings['build_params'] = build_params + build_settings["build_variant"] = build_settings_data.get("build_variant", DEFAULT_BUILD_VARIANT) + return build_settings @@ -145,7 +148,8 @@ def _build_aar(args): '-DheadersDir=' + header_files_path, '-DpublishDir=' + aar_publish_dir, '-DminSdkVer=' + str(build_settings['android_min_sdk_version']), - '-DtargetSdkVer=' + str(build_settings['android_target_sdk_version']) + '-DtargetSdkVer=' + str(build_settings['android_target_sdk_version']), + '-DbuildVariant=' + str(build_settings['build_variant']) ] # If not using shell on Window, will not be able to find gradle in path diff --git a/tools/ci_build/github/android/default_mobile_aar_build_settings.json b/tools/ci_build/github/android/default_mobile_aar_build_settings.json index e265461f6e..f8708044ac 100644 --- a/tools/ci_build/github/android/default_mobile_aar_build_settings.json +++ b/tools/ci_build/github/android/default_mobile_aar_build_settings.json @@ -7,6 +7,7 @@ ], "android_min_sdk_version": 21, "android_target_sdk_version": 24, + "build_variant": "Mobile", "build_params": [ "--android", "--parallel", diff --git a/tools/ci_build/github/azure-pipelines/mac-react-native-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-react-native-ci-pipeline.yml index 64fb9f3b5a..ce7b0d6496 100644 --- a/tools/ci_build/github/azure-pipelines/mac-react-native-ci-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/mac-react-native-ci-pipeline.yml @@ -30,6 +30,7 @@ jobs: artifactName: 'onnxruntime-android-mobile-aar' job_name_suffix: 'For_React_Native' pool_name: '${{variables.pool_name}}' + packageName: 'onnxruntime-mobile' - job: ReactNative_CI pool: @@ -100,7 +101,7 @@ jobs: npm ci workingDirectory: '$(Build.SourcesDirectory)/js' displayName: npm ci js - + - script: | npm ci workingDirectory: '$(Build.SourcesDirectory)/js/common' @@ -277,14 +278,14 @@ jobs: contents: onnxruntime-common*.tgz targetFolder: $(Build.ArtifactStagingDirectory) displayName: 'Create Artifacts onnxruntime-common' - + - task: CopyFiles@2 inputs: sourceFolder: $(Build.SourcesDirectory)/js/react_native contents: onnxruntime-react-native*.tgz targetFolder: $(Build.ArtifactStagingDirectory) displayName: Create Artifacts onnxruntime-react-native - + - task: PublishPipelineArtifact@0 inputs: artifactName: 'NPM_packages' 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 619b796db2..8dbee4491d 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 @@ -9,6 +9,12 @@ parameters: type: string default: '' +- name: packageName + # now we can build onnxruntime-android or onnxruntime-mobile for Android, need specify it here + displayName: Package Name + type: string + default: 'onnxruntime-android' + jobs: - job: Final_AAR_Testing_Android_${{ parameters.job_name_suffix }} workspace: @@ -49,7 +55,7 @@ jobs: cp -av $(Build.SourcesDirectory)/java/src/test/android ./ cd ./android mkdir -p app/libs - cp $(Build.BinariesDirectory)/final-android-aar/onnxruntime-mobile-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-mobile.aar + cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-mobile.aar $(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest displayName: Run E2E test using Emulator workingDirectory: $(Build.BinariesDirectory) 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 19397f8445..8a6a2959e2 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 @@ -35,6 +35,12 @@ parameters: type: string default: 'Linux-CPU' +- name: packageName + # now we can build onnxruntime or onnxruntime-mobile for Android, need specify it here + displayName: Package Name + type: string + default: 'onnxruntime-android' + jobs: - job: Android_Java_API_AAR_Packaging_${{ parameters.job_name_suffix }} timeoutInMinutes: 120 @@ -88,6 +94,7 @@ jobs: -e BUILD_CONFIG=${{parameters.buildConfig}} \ -e ORT_VERSION=$(OnnxRuntimeVersion) \ -e PUBLISH_EXECUTABLES=${{parameters.publish_executables}} \ + -e PACKAGE_NAME=${{parameters.packageName}} \ onnxruntimecpubuild \ /bin/bash /onnxruntime_src/tools/ci_build/github/android/build_aar_and_copy_artifacts.sh workingDirectory: $(Build.SourcesDirectory) diff --git a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml index efa51d8966..43f2580ddc 100644 --- a/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml +++ b/tools/ci_build/github/azure-pipelines/templates/c-api-cpu.yml @@ -183,6 +183,7 @@ jobs: includedOpsConfig: '$(Build.SourcesDirectory)/tools/ci_build/github/android/mobile_package.required_operators.config' artifactName: 'onnxruntime-android-mobile-aar' job_name_suffix: 'Mobile' + packageName: 'onnxruntime-mobile' - template: android-java-api-aar.yml parameters: @@ -1061,5 +1062,9 @@ jobs: parameters: artifactName: 'onnxruntime-android-mobile-aar' job_name_suffix: 'Mobile' + packageName: 'onnxruntime-mobile' - +- template: android-java-api-aar-test.yml + parameters: + artifactName: 'onnxruntime-android-full-aar' + job_name_suffix: 'Full' diff --git a/tools/ci_build/github/js/react_native_e2e_mobile_aar_build_settings.json b/tools/ci_build/github/js/react_native_e2e_mobile_aar_build_settings.json index b1e92f1446..743c02b455 100644 --- a/tools/ci_build/github/js/react_native_e2e_mobile_aar_build_settings.json +++ b/tools/ci_build/github/js/react_native_e2e_mobile_aar_build_settings.json @@ -4,6 +4,7 @@ ], "android_min_sdk_version": 21, "android_target_sdk_version": 24, + "build_variant": "Mobile", "build_params": [ "--android", "--parallel", @@ -18,4 +19,4 @@ "--use_nnapi", "--skip_tests" ] -} +} \ No newline at end of file diff --git a/tools/ci_build/github/windows/extract_nuget_files.ps1 b/tools/ci_build/github/windows/extract_nuget_files.ps1 index 3ce53b7884..b149411342 100644 --- a/tools/ci_build/github/windows/extract_nuget_files.ps1 +++ b/tools/ci_build/github/windows/extract_nuget_files.ps1 @@ -10,16 +10,16 @@ New-Item -Path $nuget_artifacts_dir -ItemType directory ## .zip files # unzip directly -Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.zip | +Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.zip | Foreach-Object { $cmd = "7z.exe x $($_.FullName) -y -o$nuget_artifacts_dir" Write-Output $cmd - Invoke-Expression -Command $cmd + Invoke-Expression -Command $cmd } ## .tgz files # first extract the tar file from the tgz -Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tgz | +Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tgz | Foreach-Object { $cmd = "7z.exe x $($_.FullName) -y -o$Env:BUILD_BINARIESDIRECTORY\nuget-artifact" Write-Output $cmd @@ -27,16 +27,17 @@ Foreach-Object { } # now extract the actual folder structure from the tar file to the build dir -Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tar | +Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter *.tar | Foreach-Object { $cmd = "7z.exe x $($_.FullName) -y -o$nuget_artifacts_dir" Write-Output $cmd Invoke-Expression -Command $cmd } -# copy android AAR. -# should only be one .aar file called onnxruntime-mobile-x.y.z.aar but sanity check that -$aars = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter onnxruntime-mobile-*.aar +# copy android AAR. +# for full build of onnxruntime Android AAR, there should only be one .aar file +# called onnxruntime-android-x.y.z.aar but sanity check that +$aars = Get-ChildItem $Env:BUILD_BINARIESDIRECTORY\nuget-artifact -Filter onnxruntime-android-*.aar if ($aars.Count -eq 1) { $aar = $aars[0] @@ -61,11 +62,11 @@ Copy-Item -Path $Env:BUILD_BINARIESDIRECTORY\extra-artifact\protoc.exe $Env:BUIL $ort_dirs = Get-ChildItem -Directory -Path $nuget_artifacts_dir\onnxruntime-* foreach ($ort_dir in $ort_dirs) { - # remove the last '-xxx' segment from the dir name. typically that's the architecture. + # remove the last '-xxx' segment from the dir name. typically that's the architecture. $dirname = Split-Path -Path $ort_dir -Leaf $dirname = $dirname.SubString(0,$dirname.LastIndexOf('-')) Write-Output "Renaming $ort_dir to $dirname" - Rename-Item -Path $ort_dir -NewName $nuget_artifacts_dir\$dirname + Rename-Item -Path $ort_dir -NewName $nuget_artifacts_dir\$dirname } # List artifacts