- Update Gradle version used in most places from 6.8.3 to 8.0.1. Update Android Gradle Plugin version where applicable.
  Not updated in this change: React Native Android projects (under `js/react_native/`). That can be done later along with updating the React Native projects.

- Add Gradle wrapper in `java/` to make it easier to consistently use a specific Gradle version.
This commit is contained in:
Edward Chen 2023-03-08 12:22:06 -08:00 коммит произвёл GitHub
Родитель d9436407b6
Коммит c46c7ccba5
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
31 изменённых файлов: 435 добавлений и 119 удалений

3
.gitignore поставляемый
Просмотреть файл

@ -41,9 +41,6 @@ onnxprofile_profile_test_*.json
/csharp/src/Microsoft.ML.OnnxRuntime/targets/**/*.props
cmake/external/FeaturizersLibrary/
# Java specific ignores
java/gradlew
java/gradlew.bat
java/gradle
java/.gradle
java/hs_*.log
onnxruntime/python/version_info.py

Просмотреть файл

@ -19,17 +19,7 @@ else()
set(JAVA_DEPENDS onnxruntime)
endif()
# use the gradle wrapper if it exists
if(EXISTS "${JAVA_ROOT}/gradlew")
set(GRADLE_EXECUTABLE "${JAVA_ROOT}/gradlew")
else()
# fall back to gradle on our PATH
find_program(GRADLE_EXECUTABLE gradle)
if(NOT GRADLE_EXECUTABLE)
message(SEND_ERROR "Gradle installation not found")
endif()
endif()
message(STATUS "Using gradle: ${GRADLE_EXECUTABLE}")
set(GRADLE_EXECUTABLE "${JAVA_ROOT}/gradlew")
# Specify the Java source files
file(GLOB_RECURSE onnxruntime4j_gradle_files "${JAVA_ROOT}/*.gradle")
@ -219,7 +209,16 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:onnxruntime> ${ANDROID_PACKAGE_ABI_DIR}/$<TARGET_LINKER_FILE_NAME:onnxruntime>)
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:onnxruntime4j_jni> ${ANDROID_PACKAGE_ABI_DIR}/$<TARGET_LINKER_FILE_NAME:onnxruntime4j_jni>)
# Generate the Android AAR package
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} -b build-android.gradle -c settings-android.gradle build -DjniLibsDir=${ANDROID_PACKAGE_JNILIBS_DIR} -DbuildDir=${ANDROID_PACKAGE_OUTPUT_DIR} -DminSdkVer=${ANDROID_MIN_SDK} -DheadersDir=${ANDROID_HEADERS_DIR} WORKING_DIRECTORY ${JAVA_ROOT})
add_custom_command(TARGET onnxruntime4j_jni
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Generating Android AAR package..."
COMMAND ${GRADLE_EXECUTABLE}
build
-b build-android.gradle -c settings-android.gradle
-DjniLibsDir=${ANDROID_PACKAGE_JNILIBS_DIR} -DbuildDir=${ANDROID_PACKAGE_OUTPUT_DIR}
-DminSdkVer=${ANDROID_MIN_SDK} -DheadersDir=${ANDROID_HEADERS_DIR}
--stacktrace
WORKING_DIRECTORY ${JAVA_ROOT})
if (onnxruntime_BUILD_UNIT_TESTS)
set(ANDROID_TEST_PACKAGE_ROOT ${JAVA_ROOT}/src/test/android)
@ -232,7 +231,13 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
# Copy the built Android AAR package to libs folder of our test app
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${ANDROID_PACKAGE_OUTPUT_DIR}/outputs/aar/onnxruntime-debug.aar ${ANDROID_TEST_PACKAGE_LIB_DIR}/onnxruntime-mobile.aar)
# Build Android test apk for java package
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} clean WORKING_DIRECTORY ${ANDROID_TEST_PACKAGE_DIR})
add_custom_command(TARGET onnxruntime4j_jni POST_BUILD COMMAND ${GRADLE_EXECUTABLE} assembleDebug assembleDebugAndroidTest -DminSdkVer=${ANDROID_MIN_SDK} WORKING_DIRECTORY ${ANDROID_TEST_PACKAGE_DIR})
add_custom_command(TARGET onnxruntime4j_jni
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "Building and running Android test for Android AAR package..."
COMMAND ${GRADLE_EXECUTABLE}
clean assembleDebug assembleDebugAndroidTest
-DminSdkVer=${ANDROID_MIN_SDK}
--stacktrace
WORKING_DIRECTORY ${ANDROID_TEST_PACKAGE_DIR})
endif()
endif()

Просмотреть файл

@ -1477,9 +1477,7 @@ if (NOT onnxruntime_BUILD_WEBASSEMBLY)
add_custom_command(TARGET custom_op_library POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different $<TARGET_FILE:custom_op_library>
${JAVA_NATIVE_TEST_DIR}/$<TARGET_FILE_NAME:custom_op_library>)
# On windows ctest requires a test to be an .exe(.com) file
# So there are two options 1) Install Chocolatey and its gradle package
# That package would install gradle.exe shim to its bin so ctest could run gradle.exe
# 2) With standard installation we get gradle.bat. We delegate execution to a separate .cmake file
# With gradle wrapper we get gradlew.bat. We delegate execution to a separate .cmake file
# That can handle both .exe and .bat
add_test(NAME onnxruntime4j_test COMMAND ${CMAKE_COMMAND}
-DGRADLE_EXECUTABLE=${GRADLE_EXECUTABLE}

Просмотреть файл

@ -15,12 +15,10 @@ Use the main project's [build instructions](https://www.onnxruntime.ai/docs/how-
#### Requirements
JDK version 8 or later is required.
The [Gradle](https://gradle.org/) build system is required and used here to manage the Java project's dependency management, compilation, testing, and assembly.
You may use your system Gradle installation installed on your PATH.
Version 6 or newer is recommended.
Optionally, you may use your own Gradle [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) which will be locked to a version specified in the `build.gradle` configuration.
This can be done once by using system Gradle installation to invoke the wrapper task in the java project's directory: `cd REPO_ROOT/java && gradle wrapper`
Any installed wrapper is gitignored.
The [Gradle](https://gradle.org/) build system is used here to manage the Java project's dependency management, compilation, testing, and assembly.
In particular, the Gradle [wrapper](https://docs.gradle.org/current/userguide/gradle_wrapper.html) at `java/gradlew[.bat]` is used, locking the Gradle version to the one specified in the `java/gradle/wrapper/gradle-wrapper.properties` configuration.
Using the Gradle wrapper removes the need to have the right version of Gradle installed on the system.
#### Build Output
@ -30,7 +28,7 @@ The build will generate output in `$REPO_ROOT/build/$OS/$CONFIGURATION/java/buil
* `reports/` - detailed test results and other reports
* `libs/onnxruntime-VERSION.jar` - JAR with compiled classes, platform-specific JNI shared library, and platform-specific onnxruntime shared library.
#### Build System Overview
#### Build System Overview
The main CMake build system delegates building and testing to Gradle.
This allows the CMake system to ensure all of the C/C++ compilation is achieved prior to the Java build.

Просмотреть файл

@ -44,7 +44,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.android.tools.build:gradle:7.4.2'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
@ -59,8 +59,7 @@ allprojects {
}
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
compileSdkVersion 32
defaultConfig {
minSdkVersion minSdkVer
@ -96,10 +95,11 @@ android {
}
}
namespace 'ai.onnxruntime'
}
task sourcesJar(type: Jar) {
classifier "sources"
archiveClassifier = "sources"
from android.sourceSets.main.java.srcDirs
}
@ -109,7 +109,7 @@ task javadoc(type: Javadoc) {
}
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from javadoc.destinationDir
}

Просмотреть файл

@ -62,10 +62,6 @@ task javadocJar(type: Jar, dependsOn: javadoc) {
}
}
wrapper {
gradleVersion = '6.1.1'
}
spotless {
java {
removeUnusedImports()

Двоичные данные
java/gradle/wrapper/gradle-wrapper.jar поставляемый Normal file

Двоичный файл не отображается.

7
java/gradle/wrapper/gradle-wrapper.properties поставляемый Normal file
Просмотреть файл

@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=1b6b558be93f29438d3df94b7dfee02e794b94d9aca4611a92cdb79b6b88e909
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

244
java/gradlew поставляемый Executable file
Просмотреть файл

@ -0,0 +1,244 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
#
# Gradle start up script for POSIX generated by Gradle.
#
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
app_path=$0
# Need this for daisy-chained symlinks.
while
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
[ -h "$app_path" ]
do
ls=$( ls -ld "$app_path" )
link=${ls#*' -> '}
case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
warn () {
echo "$*"
} >&2
die () {
echo
echo "$*"
echo
exit 1
} >&2
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "$( uname )" in #(
CYGWIN* ) cygwin=true ;; #(
Darwin* ) darwin=true ;; #(
MSYS* | MINGW* ) msys=true ;; #(
NONSTOP* ) nonstop=true ;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD=$JAVA_HOME/jre/sh/java
else
JAVACMD=$JAVA_HOME/bin/java
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
fi
# Collect all arguments for the java command, stacking in reverse order:
# * args from the command line
# * the main class name
# * -classpath
# * -D...appname settings
# * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# For Cygwin or MSYS, switch paths to Windows format before running java
if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
JAVACMD=$( cygpath --unix "$JAVACMD" )
# Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@"

92
java/gradlew.bat поставляемый Normal file
Просмотреть файл

@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal
set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.
goto fail
:execute
@rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
:mainEnd
if "%OS%"=="Windows_NT" endlocal
:omega

Просмотреть файл

@ -1,2 +1 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ai.onnxruntime" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android" />

Просмотреть файл

@ -19,8 +19,9 @@ This android application is mainly aimed for testing:
### Requirements
- JDK version 8 or later is required.
- The [Gradle](https://gradle.org/) build system is required for building the APKs used to run [android instrumentation tests](https://source.android.com/compatibility/tests/development/instrumentation). Version 6 or newer is required.
- JDK version 11 or later is required.
- The [Gradle](https://gradle.org/) build system is required for building the APKs used to run [android instrumentation tests](https://source.android.com/compatibility/tests/development/instrumentation). Version 7.5 or newer is required.
The Gradle wrapper at `java/gradlew[.bat]` may be used.
### Building

Просмотреть файл

@ -6,13 +6,12 @@ plugins {
def minSdkVer = System.properties.get("minSdkVer")?:24
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
compileSdkVersion 32
defaultConfig {
applicationId "ai.onnxruntime.example.javavalidator"
minSdkVersion minSdkVer
targetSdkVersion 30
targetSdkVersion 32
versionCode 1
versionName "1.0"
@ -32,6 +31,7 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
namespace 'ai.onnxruntime.example.javavalidator'
}
dependencies {

Просмотреть файл

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ai.onnxruntime.example.javavalidator">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application
android:allowBackup="true"
@ -9,7 +8,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.JavaValidator">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Просмотреть файл

@ -1,13 +1,13 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.4.32"
ext.kotlin_version = '1.6.21'
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.0.1"
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

Просмотреть файл

@ -6,7 +6,7 @@
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx4096m -Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
@ -18,4 +18,4 @@ android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
kotlin.code.style=official

Просмотреть файл

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=7faa7198769f872826c8ef4f1450f839ec27f0b4d5d1e51bade63667cbccd205
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Просмотреть файл

@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=7faa7198769f872826c8ef4f1450f839ec27f0b4d5d1e51bade63667cbccd205
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

Просмотреть файл

@ -53,6 +53,8 @@ RUN CMAKE_VERSION=3.25.2 && \
tar -zxf /tmp/cmake-${CMAKE_VERSION}-linux-x86_64.tar.gz --strip=1 -C /usr
# gradle
# Note: A system-installed gradle is not required in more recent versions of ORT which use an included gradle wrapper,
# but keep it around to support building older versions.
RUN GRADLE_VERSION=6.8.3 && \
aria2c -q -d /tmp -o gradle-${GRADLE_VERSION}-bin.zip \
--checksum=sha-256=7faa7198769f872826c8ef4f1450f839ec27f0b4d5d1e51bade63667cbccd205 \

Просмотреть файл

@ -1580,7 +1580,7 @@ def run_android_tests(args, source_dir, build_dir, config, cwd):
with contextlib.ExitStack() as context_stack:
if args.android_run_emulator:
avd_name = "ort_android"
system_image = "system-images;android-{};google_apis;{}".format(args.android_api, args.android_abi)
system_image = "system-images;android-{};default;{}".format(args.android_api, args.android_abi)
android.create_virtual_device(sdk_tool_paths, system_image, avd_name)
emulator_proc = context_stack.enter_context(
@ -1603,11 +1603,8 @@ def run_android_tests(args, source_dir, build_dir, config, cwd):
run_adb_shell("{0}/onnxruntime_test_all".format(device_dir))
if args.build_java:
gradle_executable = "gradle"
# use the gradle wrapper if it exists, the gradlew should be setup under <repo root>/java
gradlew_path = os.path.join(source_dir, "java", "gradlew.bat" if is_windows() else "gradlew")
if os.path.exists(gradlew_path):
gradle_executable = gradlew_path
# use the gradle wrapper under <repo root>/java
gradle_executable = os.path.join(source_dir, "java", "gradlew.bat" if is_windows() else "gradlew")
android_test_path = os.path.join(cwd, "java", "androidtest", "android")
run_subprocess(
[

Просмотреть файл

@ -134,9 +134,11 @@ def _build_aar(args):
aar_publish_dir = os.path.join(build_dir, "aar_out", build_config)
os.makedirs(aar_publish_dir, exist_ok=True)
gradle_path = os.path.join(JAVA_ROOT, "gradlew" if not is_windows() else "gradlew.bat")
# get the common gradle command args
gradle_command = [
"gradle",
gradle_path,
"--no-daemon",
"-b=build-android.gradle",
"-c=settings-android.gradle",
@ -149,13 +151,10 @@ def _build_aar(args):
"-DbuildVariant=" + str(build_settings["build_variant"]),
]
# If not using shell on Window, will not be able to find gradle in path
use_shell = True if is_windows() else False
# clean, build, and publish to a local directory
subprocess.run(gradle_command + ["clean"], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT)
subprocess.run(gradle_command + ["build"], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT)
subprocess.run(gradle_command + ["publish"], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT)
subprocess.run(gradle_command + ["clean"], env=temp_env, shell=False, check=True, cwd=JAVA_ROOT)
subprocess.run(gradle_command + ["build"], env=temp_env, shell=False, check=True, cwd=JAVA_ROOT)
subprocess.run(gradle_command + ["publish"], env=temp_env, shell=False, check=True, cwd=JAVA_ROOT)
def parse_args():

Просмотреть файл

@ -46,8 +46,6 @@ stages:
- template: "templates/use-android-ndk.yml"
- template: templates/set-up-gradle-wrapper-step.yml
# We build the host protoc to <ORT_ROOT>/protobuf_install
- script: |
/bin/bash $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_host_protoc.sh \
@ -130,8 +128,6 @@ stages:
- template: "templates/use-android-ndk.yml"
- template: templates/set-up-gradle-wrapper-step.yml
# We build the host protoc to <ORT_ROOT>/protobuf_install
- script: |
/bin/bash $(Build.SourcesDirectory)/tools/ci_build/github/apple/build_host_protoc.sh \
@ -233,12 +229,10 @@ stages:
- template: "templates/use-android-ndk.yml"
- template: templates/set-up-gradle-wrapper-step.yml
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-30;google_apis;x86_64" \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
@ -305,12 +299,10 @@ stages:
- template: "templates/use-android-ndk.yml"
- template: templates/set-up-gradle-wrapper-step.yml
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-30;google_apis;x86_64" \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
@ -387,8 +379,6 @@ stages:
- template: "templates/use-android-ndk.yml"
- template: templates/set-up-gradle-wrapper-step.yml
# used by Build Minimal ORT
- script: brew install coreutils ninja
displayName: Install coreutils and ninja
@ -404,7 +394,7 @@ stages:
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-29;google_apis;x86_64" \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator

Просмотреть файл

@ -105,7 +105,7 @@ stages:
cp $(Build.SourcesDirectory)/tools/ci_build/github/linux/docker/scripts/training/ortmodule/stage1/requirements_torch_cpu/requirements.txt $(Build.BinariesDirectory)/requirements_torch_cpu/requirements.txt
python3 -m pip install -r $(Build.BinariesDirectory)/requirements_torch_cpu/requirements.txt
cd $(Build.SourcesDirectory)/java
/usr/local/gradle/bin/gradle "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release"
$(Build.SourcesDirectory)/java/gradlew "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release"
- task: CmdLine@2
displayName: 'Install Release python package'
@ -187,7 +187,7 @@ stages:
devtoolset_rootpath: /opt/rh/devtoolset-10/root
ld_library_path_arg: /opt/rh/devtoolset-10/root/usr/lib64:/opt/rh/devtoolset-10/root/usr/lib:/opt/rh/devtoolset-10/root/usr/lib64/dyninst:/opt/rh/devtoolset-10/root/usr/lib/dyninst:/usr/local/lib64
prepend_path: '/opt/rh/devtoolset-10/root/usr/bin:'
- stage: arm64_test
dependsOn: ['arm64_build']
jobs:
@ -195,4 +195,4 @@ stages:
parameters:
arch: 'aarch64'
machine_pool: 'onnxruntime-linux-ARM64-CPU-2019'
device: 'CPU'
device: 'CPU'

Просмотреть файл

@ -133,7 +133,7 @@ jobs:
# Restore file permissions
xargs -a $(Build.BinariesDirectory)/Release/perms.txt chmod a+x
cd $(Build.SourcesDirectory)/java
/usr/local/gradle/bin/gradle "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release" "-DUSE_CUDA=1"
$(Build.SourcesDirectory)/java/gradlew "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release" "-DUSE_CUDA=1"
cd /tmp
python3 $(Build.SourcesDirectory)/tools/ci_build/build.py \
--build_dir $(Build.BinariesDirectory) --cmake_generator Ninja \

Просмотреть файл

@ -77,7 +77,7 @@ jobs:
python3 -m pip install -r $(Build.BinariesDirectory)/requirements_torch_cpu/requirements.txt
ln -sf /data/models $(Build.BinariesDirectory)
cd $(Build.SourcesDirectory)/java
/usr/local/gradle/bin/gradle "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release"
$(Build.SourcesDirectory)/java/gradlew "cmakeCheck" "-DcmakeBuildDir=$(Build.BinariesDirectory)/Release"
- task: CmdLine@2
displayName: 'Install Release python package'

Просмотреть файл

@ -37,14 +37,19 @@ jobs:
artifactName: '${{parameters.artifactName}}'
targetPath: '$(Build.BinariesDirectory)/final-android-aar'
- template: use-android-ndk.yml
- task: JavaToolInstaller@0
displayName: Use jdk 11
inputs:
versionSpec: '11'
jdkArchitectureOption: 'x64'
jdkSourceOption: 'PreInstalled'
- template: set-up-gradle-wrapper-step.yml
- template: use-android-ndk.yml
- script: |
python3 $(Build.SourcesDirectory)/tools/python/run_android_emulator.py \
--android-sdk-root ${ANDROID_SDK_ROOT} \
--create-avd --system-image "system-images;android-30;google_apis;x86_64" \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android emulator
@ -57,7 +62,7 @@ jobs:
cd ./android
mkdir -p app/libs
cp $(Build.BinariesDirectory)/final-android-aar/${{parameters.packageName}}-$(OnnxRuntimeVersion).aar app/libs/onnxruntime-mobile.aar
$(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest
$(Build.SourcesDirectory)/java/gradlew --no-daemon clean connectedDebugAndroidTest --stacktrace
displayName: Run E2E test using Emulator
workingDirectory: $(Build.BinariesDirectory)

Просмотреть файл

@ -50,8 +50,6 @@ jobs:
- template: set-version-number-variables-step.yml
- template: set-up-gradle-wrapper-step.yml
- script: |
brew install ccache
echo "##vso[task.prependpath]/usr/local/opt/ccache/libexec"

Просмотреть файл

@ -60,8 +60,6 @@ jobs:
brew install coreutils ninja npm yarn
displayName: Install coreutils, ninja, npm, and yarn
- template: set-up-gradle-wrapper-step.yml
- script: |
python3 -m pip install -q flatbuffers
displayName: Install python modules
@ -131,7 +129,7 @@ jobs:
- script: |
python3 tools/python/run_android_emulator.py \
--android-sdk-root $(ANDROID_SDK_ROOT) \
--create-avd --system-image "system-images;android-30;google_apis;x86_64" \
--create-avd --system-image "system-images;android-31;default;x86_64" \
--start --emulator-extra-args="-partition-size 4096" \
--emulator-pid-file $(Build.BinariesDirectory)/emulator.pid
displayName: Start Android Emulator

Просмотреть файл

@ -1,10 +0,0 @@
parameters:
- name: GradleWrapperVersion
type: string
default: "6.8.3"
steps:
- script: |
gradle wrapper --gradle-version="${{ parameters.GradleWrapperVersion }}" --no-daemon --no-watch-fs
displayName: Set up gradle ${{ parameters.GradleWrapperVersion }} wrapper
workingDirectory: $(Build.SourcesDirectory)/java

Просмотреть файл

@ -52,7 +52,7 @@ parameters:
type: string
default: 'onnxruntime'
- name: UseIncreasedTimeoutForTests
- name: UseIncreasedTimeoutForTests
displayName: Increase timeout for tests? Set it to false if you are doing an Onnx Runtime release.
type: boolean
default: false
@ -63,9 +63,9 @@ jobs:
clean: all
pool: ${{ parameters.ort_build_pool_name }}
${{ if eq(parameters['UseIncreasedTimeoutForTests'], 'true') }}:
timeoutInMinutes: 1200
timeoutInMinutes: 1200
${{ else }}:
timeoutInMinutes: 300
timeoutInMinutes: 300
steps:
- checkout: self
@ -73,11 +73,11 @@ jobs:
submodules: none
- template: telemetry-steps.yml
- task: UsePythonVersion@0
inputs:
versionSpec: '3.7'
addToPath: true
inputs:
versionSpec: '3.7'
addToPath: true
architecture: ${{ parameters.buildArch }}
- task: NodeTool@0
@ -119,7 +119,7 @@ jobs:
${{ else }}:
arguments: '--config RelWithDebInfo --enable_lto --disable_rtti --build_dir $(Build.BinariesDirectory) --skip_submodule_sync --build_shared_lib --update --cmake_generator "Visual Studio 16 2019" --enable_onnx_tests $(TelemetryOption) ${{ parameters.buildparameter }} '
workingDirectory: '$(Build.BinariesDirectory)'
- task: VSBuild@1
displayName: 'Build'
inputs:
@ -144,7 +144,7 @@ jobs:
dir *.dll
mkdir $(Build.ArtifactStagingDirectory)\testdata
workingDirectory: '$(Build.BinariesDirectory)/RelWithDebInfo/RelWithDebInfo'
displayName: 'List built DLLs'
displayName: 'List built DLLs'
- template: c-api-artifacts-package-and-publish-steps-windows.yml
parameters:
@ -166,7 +166,7 @@ jobs:
condition: and(succeeded(), eq('${{ parameters.packageName}}', 'x64'))
inputs:
targetPath: '$(Build.BinariesDirectory)\RelWithDebInfo\installed\bin\protoc.exe'
artifactName: 'drop-extra'
artifactName: 'drop-extra'
- task: CopyFiles@2
@ -187,11 +187,12 @@ jobs:
- task: CmdLine@2
condition: and(succeeded(), eq('${{ parameters.buildJava}}', true))
displayName: 'Add symbols and notices to Java'
inputs:
script: |
@echo on
cd $(Build.SourcesDirectory)\java
gradle cmakeCheck -DcmakeBuildDir=$(Build.BinariesDirectory)\RelWithDebInfo
call $(Build.SourcesDirectory)\java\gradlew.bat cmakeCheck -DcmakeBuildDir=$(Build.BinariesDirectory)\RelWithDebInfo
if %errorlevel% neq 0 exit /b %errorlevel%
cd $(Build.BinariesDirectory)\RelWithDebInfo
set NATIVE_FOLDER=$(Build.BinariesDirectory)\onnxruntime-java-win-${{ parameters.msbuildPlatform }}\stage\ai\onnxruntime\native\win-x64
@ -225,14 +226,12 @@ jobs:
popd
rd /s /q $(Build.BinariesDirectory)\onnxruntime-java-win-${{ parameters.msbuildPlatform }}\stage
dir /s /b $(Build.BinariesDirectory)\onnxruntime-java-win-${{ parameters.msbuildPlatform }}
workingDirectory: '$(Build.BinariesDirectory)\RelWithDebInfo'
displayName: 'Add symbols and notices to Java'
- task: PublishBuildArtifacts@1
condition: and(succeeded(), eq('${{ parameters.buildJava}}', true))
displayName: 'Publish Java temp binaries'
inputs:
pathtoPublish: '$(Build.BinariesDirectory)\onnxruntime-java-win-${{ parameters.msbuildPlatform }}'
pathtoPublish: '$(Build.BinariesDirectory)\onnxruntime-java-win-${{ parameters.msbuildPlatform }}'
artifactName: 'drop-onnxruntime-java-win-${{ parameters.packageName }}'
- ${{ if eq(parameters['DoCompliance'], 'true') }}:
@ -241,8 +240,8 @@ jobs:
inputs:
sourceCodeDirectory: '$(Build.SourcesDirectory)\java'
language: 'java'
cleanupBuildCommands: 'C:\ProgramData\chocolatey\bin\gradle.exe -Dorg.gradle.daemon=false clean'
buildCommands: 'C:\ProgramData\chocolatey\bin\gradle.exe -Dorg.gradle.daemon=false jar'
cleanupBuildCommands: '$(Build.SourcesDirectory)\java\gradlew.bat -Dorg.gradle.daemon=false clean'
buildCommands: '$(Build.SourcesDirectory)\java\gradlew.bat -Dorg.gradle.daemon=false jar'
querySuite: 'Recommended'
timeout: '7200'
ram: '16384'
@ -268,7 +267,7 @@ jobs:
**/*.obj
**/*.pdb
**/*.dll
#Manually set msBuildCommandline so that we can also set CAExcludePath
- task: SDLNativeRules@3
displayName: 'Run the PREfast SDL Native Rules for MSBuild'

Просмотреть файл

@ -28,7 +28,7 @@ def parse_args():
parser.add_argument("--android-sdk-root", required=True, help="Path to the Android SDK root.")
parser.add_argument(
"--system-image",
default="system-images;android-29;google_apis;x86_64",
default="system-images;android-31;default;x86_64",
help="The Android system image package name.",
)
parser.add_argument("--avd-name", default="ort_android", help="The Android virtual device name.")