diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 1f4ae7da..4ddb7de4 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -65,14 +65,14 @@ jobs: if [[ "${{ runner.os }}" == "Windows" ]]; then SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat fi - ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620' + ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370' shell: bash - - name: Setup Java 17 + - name: Setup Java 25 uses: actions/setup-java@v5 with: distribution: 'temurin' - java-version: 17 + java-version: 25 cache: 'gradle' - name: Assemble samples/app @@ -83,6 +83,12 @@ jobs: run: | ./gradlew -p samples/library :assembleDebug --info --warning-mode all + - name: Test samples/unittest + if: runner.os == 'Linux' + run: | + echo 'rust.targets=x86_64,linux-x86-64' > samples/unittest/local.properties + ./gradlew -p samples/unittest testDebugUnitTest --info --warning-mode all + # Work around https://github.com/actions/cache/issues/454. - name: Gradle stop run: | @@ -116,15 +122,15 @@ jobs: if [[ "${{ runner.os }}" == "Windows" ]]; then SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat fi - ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620' + ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370' shell: bash - # Use Java 17 - - name: Setup Java 17 + # Use Java 25 + - name: Setup Java 25 uses: actions/setup-java@v5 with: distribution: 'temurin' - java-version: 17 + java-version: 25 cache: 'gradle' - name: Gradle setup @@ -167,7 +173,7 @@ jobs: if [[ "${{ runner.os }}" == "Windows" ]]; then SDKMANAGER=$(echo $SDKMANAGER | tr '/' '\').bat fi - ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;21.4.7075529' 'ndk;23.1.7779620' + ${ANDROID_HOME}${SDKMANAGER} --install 'ndk;30.0.16248370' shell: bash - name: Setup Rust stable @@ -175,12 +181,12 @@ jobs: with: targets: x86_64-linux-android,x86_64-unknown-linux-gnu,aarch64-linux-android - # Use Java 17 - - name: Setup Java 17 + # Use Java 25 + - name: Setup Java 25 uses: actions/setup-java@v5 with: distribution: 'temurin' - java-version: 17 + java-version: 25 cache: 'gradle' - name: Gradle setup diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 36b79843..ee2c1c72 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -11,10 +11,10 @@ jobs: steps: - uses: actions/checkout@v7 - - name: Set up JDK 17 + - name: Set up JDK 25 uses: actions/setup-java@v5 with: - java-version: 17 + java-version: 25 distribution: 'temurin' - name: Write gradle.properties diff --git a/.gitignore b/.gitignore index 740f9e1f..37fcc3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -39,4 +39,5 @@ gradle-app.setting .gradletasknamecache .cargo -**/maven-repo/ \ No newline at end of file +**/maven-repo/ +.kotlin/ diff --git a/README.md b/README.md index 2ce15661..90acc09d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,9 @@ Cross compile Rust Cargo projects for Android targets. +Requires Android Gradle Plugin 9.0 or newer and Gradle 9.1 or newer. Projects still on Android Gradle Plugin 8 +can keep using the 0.10.0 release. +

@@ -70,14 +73,8 @@ Finally, run the `cargoBuild` task to cross compile: ```sh ./gradlew cargoBuild ``` -Or add it as a dependency to one of your other build tasks, to build your rust code when you normally build your project: -```gradle -tasks.whenTaskAdded { task -> - if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) { - task.dependsOn 'cargoBuild' - } -} -``` +Each variant's jniLibs merge and unit test tasks depend on `cargoBuild`, so building or testing the project +builds the Rust code first. ## Configuration @@ -448,23 +445,24 @@ and builds will likely fail.) ## Passing arguments to cargo -The plugin passes project properties named like `RUST_ANDROID_GRADLE_target_..._KEY=VALUE` through +The plugin passes project properties named like `RUST_ANDROID_GRADLE_TARGET__=VALUE` through to the Cargo invocation for the given Rust `target` as `KEY=VALUE`. Target should be upper-case with "-" replaced by "_". (See [the links from this Cargo issue](https://github.com/rust-lang/cargo/issues/5690).) So, for example, ```groovy -project.RUST_ANDROID_GRADLE_I686_LINUX_ANDROID_FOO=BAR +ext.RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO = "BAR" ``` and ```shell -./gradlew -PRUST_ANDROID_GRADLE_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ... +./gradlew -PRUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ... ``` and ``` -env ORG_GRADLE_PROJECT_RUST_ANDROID_GRADLE_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ./gradlew ... +env ORG_GRADLE_PROJECT_RUST_ANDROID_GRADLE_TARGET_ARMV7_LINUX_ANDROIDEABI_FOO=BAR ./gradlew ... ``` -all set `FOO=BAR` in the `cargo` execution environment (for the "armv7-linux-androideabi` Rust -target, corresponding to the "x86" target in the plugin). +all set `FOO=BAR` in the `cargo` execution environment for the `armv7-linux-androideabi` Rust +target, which is the `arm` target in the plugin. A `gradle.properties` entry works too. An `ext` +value must be set in the project that applies the plugin, or through `allprojects`. # Development diff --git a/build.gradle b/build.gradle index 02d12e97..27935b0f 100644 --- a/build.gradle +++ b/build.gradle @@ -2,16 +2,14 @@ buildscript { Properties versionProperties = new Properties() versionProperties.load(new FileInputStream("$project.rootDir/version.properties")) - // Kotlin 1.9.22: Required for Gradle 8.5+ (old Kotlin Gradle plugin uses removed APIs) - ext.kotlin_version = '1.9.22' - // AGP 8.2.0: Required for Gradle 8.5+ compatibility - ext.agp_version = '8.2.0' + ext.kotlin_version = '2.4.21' + ext.agp_version = '9.0.0' ext.plugin_version = versionProperties.getProperty("version") repositories { google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } dependencies { @@ -24,13 +22,13 @@ subprojects { repositories { google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } } -task clean(type: Delete) { - delete rootProject.buildDir +tasks.register('clean', Delete) { + delete rootProject.layout.buildDirectory } wrapper { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index e708b1c0..51cbd2a6 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index a5952066..6f77dd39 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,9 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.9.1-all.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4f906e0c..249efbb0 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ -#!/usr/bin/env sh +#!/bin/sh # -# Copyright 2015 the original author or authors. +# Copyright © 2015 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. @@ -15,81 +15,114 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## -## -## Gradle start up script for UN*X -## +# +# gradlew 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 gradlew +# +# 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/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/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 -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi +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 -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# 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"' +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. -MAX_FD="maximum" +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 - ;; - MINGW* ) - msys=true - ;; - NONSTOP* ) - nonstop=true - ;; +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" + JAVACMD=$JAVA_HOME/jre/sh/java else - JAVACMD="$JAVA_HOME/bin/java" + JAVACMD=$JAVA_HOME/bin/java fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME @@ -98,88 +131,118 @@ 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. + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + 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 fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi +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=SC2039,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=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac fi -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -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" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" + 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 - i=`expr $i + 1` + # 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 - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac fi -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" +# 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"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ + "$@" + +# 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" "$@" diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..03754c4c 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,19 +13,49 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions + +@rem Catch executions from older scripts and ensure they exit cleanly. +@rem This can be removed once we can be reasonably confident that few people +@rem will be migrating directly to this new wrapper. +goto afterSafetyNet +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: +goto exitWithErrorLevel +:afterSafetyNet set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,15 +70,16 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +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. +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. -goto fail +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -56,34 +87,26 @@ 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. +1>&2 echo. +1>&2 echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +1>&2 echo. +1>&2 echo Please set the JAVA_HOME variable in your environment to match the +1>&2 echo location of your Java installation. -goto fail +"%COMSPEC%" /c exit 1 +goto exitWithErrorLevel :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%"=="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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 -:mainEnd -if "%OS%"=="Windows_NT" endlocal +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel & goto exitWithErrorLevel -:omega +@rem This label must not be changed. We rely on old scripts being able to jump to this point. +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% diff --git a/plugin/build.gradle b/plugin/build.gradle index be702b3e..471c30c9 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -1,10 +1,10 @@ import groovy.json.JsonBuilder -import org.gradle.util.VersionNumber +import org.jetbrains.kotlin.gradle.dsl.JvmTarget +import org.jetbrains.kotlin.gradle.dsl.KotlinVersion plugins { - // plugin-publish 1.2.1: Required for Gradle 8.5+ (old version uses removed pluginBundle API) - id 'com.gradle.plugin-publish' version '1.2.1' - id "org.gradle.test-retry" version "1.5.8" + id 'com.gradle.plugin-publish' version '2.2.1' + id "org.gradle.test-retry" version "1.6.6" } apply plugin: "java-gradle-plugin" @@ -27,24 +27,20 @@ gradlePlugin { } } -group 'org.mozilla.rust-android-gradle' -version "$plugin_version" +group = 'org.mozilla.rust-android-gradle' +version = rootProject.ext.plugin_version def isCI = (System.getenv('CI') ?: 'false').toBoolean() // Maps supported Android plugin versions to the versions of Gradle that support it -// Updated for Gradle 8.5+ compatibility (required for Gradle 9 support) def supportedVersions = [ - "8.2.0": ["8.5"], - "8.3.0": ["8.5"], - "8.4.0": ["8.6"], - "8.5.0": ["8.7"], - "8.6.0": ["8.7"], + "9.0.0": ["9.1.0"], + "9.5.1": ["9.9.1"], ] // A local repo we publish our library to for testing in order to workaround limitations // in the TestKit plugin classpath. -def localRepo = file("$buildDir/local-repo") +def localRepo = layout.buildDirectory.dir("local-repo").get().asFile publishing { repositories { maven { @@ -55,33 +51,31 @@ publishing { dependencies { implementation gradleApi() - // Guava: Required for Versions.groovy (was transitively provided by old AGP) - implementation "com.google.guava:guava:32.1.3-jre" - compileOnly "com.android.tools.build:gradle:${agp_version}" + compileOnly "com.android.tools.build:gradle-api:${rootProject.ext.agp_version}" testImplementation gradleTestKit() - testImplementation "com.android.tools.build:gradle:${agp_version}" - testImplementation platform("org.spockframework:spock-bom:2.0-M5-groovy-3.0") - testImplementation("org.spockframework:spock-core") { exclude group: 'org.codehaus.groovy' } - testImplementation("org.spockframework:spock-junit4") { exclude group: 'org.codehaus.groovy' } - testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "com.google.guava:guava:33.8.0-jre" + testImplementation platform("org.spockframework:spock-bom:2.5-groovy-4.0") + testImplementation("org.spockframework:spock-core") { exclude group: 'org.apache.groovy' } + testImplementation("org.spockframework:spock-junit4") { exclude group: 'org.apache.groovy' } + testRuntimeOnly "org.junit.platform:junit-platform-launcher" } -// Java 17: Required for Gradle 8.5+ and AGP 8.x java { sourceCompatibility = JavaVersion.VERSION_17 targetCompatibility = JavaVersion.VERSION_17 } -compileKotlin { - kotlinOptions.jvmTarget = "17" -} -compileTestKotlin { - kotlinOptions.jvmTarget = "17" +kotlin { + compilerOptions { + jvmTarget = JvmTarget.JVM_17 + apiVersion = KotlinVersion.KOTLIN_2_2 + languageVersion = KotlinVersion.KOTLIN_2_2 + } } // Generate a json file that contains the matrix of Gradle and AGP versions to test against. -def generatedResources = "$buildDir/generated-resources/main" +def generatedResources = layout.buildDirectory.dir("generated-resources/test").get().asFile tasks.register('generateVersions') { def outputFile = file("$generatedResources/versions.json") inputs.property "version", version @@ -96,13 +90,13 @@ tasks.register('generateVersions') { } sourceSets { - main { + test { output.dir(generatedResources, builtBy: tasks.named('generateVersions')) } } // This is used by github actions to split out jobs by Android version test task -def generatedBuildResources = "$buildDir/build-resources" +def generatedBuildResources = layout.buildDirectory.dir("build-resources").get().asFile tasks.register('generateTestTasksJson') { def outputFile = file("${generatedBuildResources}/androidTestTasks.json") inputs.property "supportedVersions", supportedVersions @@ -131,14 +125,11 @@ tasks.withType(Test).configureEach { // Generate a test task for each Android version and run the tests annotated with the MultiVersionTest category supportedVersions.keySet().each { androidVersion -> def testTaskName = androidTestTaskName(androidVersion) - def jdkVersion = jdkVersionFor(androidVersion) def versionSpecificTest = tasks.register(testTaskName, Test) { - description = "Runs the multi-version tests for AGP ${androidVersion} (JDK version ${jdkVersion})" + description = "Runs the multi-version tests for AGP ${androidVersion}" group = "verification" - - javaLauncher = javaToolchains.launcherFor { - languageVersion = jdkVersion - } + testClassesDirs = sourceSets.test.output.classesDirs + classpath = sourceSets.test.runtimeClasspath systemProperty 'org.gradle.android.testVersion', androidVersion } @@ -155,11 +146,3 @@ static def androidTestTaskName(String androidVersion) { static def normalizeVersion(String version) { return version.replaceAll('[.\\-]', '_') } - -static def jdkVersionFor(String version) { - // AGP 8.x requires Java 17 - def jdkVersion = VersionNumber.parse(version) >= VersionNumber.parse("8.0.0") ? 17 : - VersionNumber.parse(version) > VersionNumber.parse("7.0.0-alpha01") ? 11 : 8 - - return JavaLanguageVersion.of(jdkVersion) -} diff --git a/plugin/src/main/kotlin/com/nishtahir/Extensions.kt b/plugin/src/main/kotlin/com/nishtahir/Extensions.kt deleted file mode 100644 index 74445e77..00000000 --- a/plugin/src/main/kotlin/com/nishtahir/Extensions.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.nishtahir - -import org.gradle.api.plugins.ExtensionContainer -import kotlin.reflect.KClass - -operator fun ExtensionContainer.get(type: KClass): T = getByType(type.java) diff --git a/plugin/src/main/kotlin/com/nishtahir/GenerateLinkerWrapperTask.kt b/plugin/src/main/kotlin/com/nishtahir/GenerateLinkerWrapperTask.kt deleted file mode 100644 index 50479ab3..00000000 --- a/plugin/src/main/kotlin/com/nishtahir/GenerateLinkerWrapperTask.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.nishtahir - -import org.gradle.api.tasks.Sync - -open class GenerateLinkerWrapperTask : Sync() { -} diff --git a/plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt b/plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt index 23732cc8..76c555a6 100644 --- a/plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt +++ b/plugin/src/main/kotlin/com/nishtahir/RustAndroidPlugin.kt @@ -1,11 +1,14 @@ package com.nishtahir -import com.android.build.gradle.* +import com.android.build.api.variant.AndroidComponentsExtension +import com.android.build.api.variant.HasUnitTest +import com.android.build.api.variant.Variant import org.gradle.api.DefaultTask import org.gradle.api.GradleException import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.file.DuplicatesStrategy +import org.gradle.api.tasks.Sync import java.io.File import java.util.Properties @@ -141,19 +144,40 @@ open class RustAndroidPlugin : Plugin { with(project) { cargoExtension = extensions.create("cargo", CargoExtension::class.java) - afterEvaluate { - plugins.all { - when (it) { - is AppPlugin -> configurePlugin(this) - is LibraryPlugin -> configurePlugin(this) - } + listOf("com.android.application", "com.android.library").forEach { id -> + pluginManager.withPlugin(id) { + configureAndroid(this) } } + } + } + + private fun configureAndroid(project: Project) = with(project) { + val androidComponents = extensions.getByType(AndroidComponentsExtension::class.java) + var minSdk: Int? = null + + androidComponents.onVariants { variant -> + minSdk = minOf(minSdk ?: Int.MAX_VALUE, variant.minSdk.apiLevel) + addCargoOutputs(variant) + } + + afterEvaluate { + configurePlugin(this, androidComponents, minSdk) + } + } + private fun Project.addCargoOutputs(variant: Variant) { + val rustJniLibs = layout.buildDirectory.dir("rustJniLibs").get().asFile + variant.sources.jniLibs?.addStaticSourceDirectory(File(rustJniLibs, "android").path) + val mergeJniLibs = "merge${variant.name.replaceFirstChar { it.titlecase() }}JniLibFolders" + tasks.named { it == mergeJniLibs }.configureEach { it.dependsOn("cargoBuild") } + (variant as? HasUnitTest)?.unitTest?.configureTestTask { + it.classpath += files(File(rustJniLibs, "desktop")) + it.dependsOn("cargoBuild") } } - private inline fun configurePlugin(project: Project) = with(project) { + private fun configurePlugin(project: Project, androidComponents: AndroidComponentsExtension<*, *, *>, minSdk: Int?) = with(project) { cargoExtension.localProperties = Properties() val localPropertiesFile = File(project.rootDir, "local.properties") @@ -188,11 +212,9 @@ open class RustAndroidPlugin : Plugin { throw GradleException("Cannot set both `apiLevel` and `apiLevels`") } } else { - val default = if (apiLevel != null) { - apiLevel - } else { - extensions[T::class].defaultConfig.minSdkVersion!!.apiLevel - } + val default = apiLevel + ?: minSdk + ?: throw GradleException("Could not determine minSdk: no Android variants were configured") cargoExtension.apiLevels = cargoExtension.targets!!.map { it to default }.toMap() } val missingApiLevelTargets = cargoExtension.targets!!.toSet().minus( @@ -201,13 +223,8 @@ open class RustAndroidPlugin : Plugin { throw GradleException("`apiLevels` missing entries for: $missingApiLevelTargets") } - extensions[T::class].apply { - sourceSets.getByName("main").jniLibs.srcDir(File("$buildDir/rustJniLibs/android")) - sourceSets.getByName("test").resources.srcDir(File("$buildDir/rustJniLibs/desktop")) - } - // Determine the NDK version, if present - val ndk = extensions[T::class].ndkDirectory.let { + val ndk = androidComponents.sdkComponents.ndkDirectory.get().asFile.let { val ndkSourceProperties = Properties() val ndkSourcePropertiesFile = File(it, "source.properties") if (ndkSourcePropertiesFile.exists()) { @@ -218,7 +235,7 @@ open class RustAndroidPlugin : Plugin { } // Fish linker wrapper scripts from our Java resources. - val generateLinkerWrapper = rootProject.tasks.maybeCreate("generateLinkerWrapper", GenerateLinkerWrapperTask::class.java).apply { + val generateLinkerWrapper = rootProject.tasks.maybeCreate("generateLinkerWrapper", Sync::class.java).apply { group = RUST_TASK_GROUP description = "Generate shared linker wrapper script" } @@ -227,7 +244,7 @@ open class RustAndroidPlugin : Plugin { // From https://stackoverflow.com/a/320595. from(rootProject.zipTree(File(RustAndroidPlugin::class.java.protectionDomain.codeSource.location.toURI()).path)) include("**/linker-wrapper*") - into(File(rootProject.buildDir, "linker-wrapper")) + into(rootProject.layout.buildDirectory.dir("linker-wrapper")) eachFile { it.path = it.path.replaceFirst("com/nishtahir", "") } @@ -251,15 +268,15 @@ open class RustAndroidPlugin : Plugin { throw GradleException("Target ${target} is not recognized (recognized targets: ${toolchains.map { it.platform }.sorted()}). Check `local.properties` and `build.gradle`.") } - val targetBuildTask = tasks.maybeCreate("cargoBuild${target.capitalize()}", + val targetBuildTask = tasks.maybeCreate("cargoBuild${target.replaceFirstChar { it.titlecase() }}", CargoBuildTask::class.java).apply { group = RUST_TASK_GROUP description = "Build library ($target)" toolchain = theToolchain this.ndk = ndk projectDir = project.projectDir - this.buildDir = project.buildDir - rootBuildDir = project.rootProject.buildDir + this.buildDir = project.layout.buildDirectory.get().asFile + rootBuildDir = project.rootProject.layout.buildDirectory.get().asFile cargoCommand = cargoExtension.cargoCommand rustcCommand = cargoExtension.rustcCommand rustupChannel = cargoExtension.rustupChannel @@ -281,7 +298,7 @@ open class RustAndroidPlugin : Plugin { "RUST_ANDROID_GRADLE_AUTO_CONFIGURE_CLANG_SYS", theToolchain.type != ToolchainType.DESKTOP ) - targetProperties = project.properties + targetProperties = project.extensions.extraProperties.properties .filterKeys { it.startsWith("RUST_ANDROID_GRADLE_TARGET_") } .mapValues { it.value?.toString() ?: "" } cargoExtension.exec?.let { diff --git a/plugin/src/test/groovy/com/nishtahir/CargoBuildTest.groovy b/plugin/src/test/groovy/com/nishtahir/CargoBuildTest.groovy index d310afb2..3e898953 100644 --- a/plugin/src/test/groovy/com/nishtahir/CargoBuildTest.groovy +++ b/plugin/src/test/groovy/com/nishtahir/CargoBuildTest.groovy @@ -28,7 +28,7 @@ class CargoBuildTest extends AbstractTest { when: BuildResult buildResult = withGradleVersion(gradleVersion.version) .withProjectDir(temporaryFolder.root) - .withArguments('cargoBuild', '--info', '--stacktrace') + .withArguments('mergeDebugJniLibFolders', '--info', '--stacktrace') // .withDebug(true) .build() @@ -40,8 +40,12 @@ class CargoBuildTest extends AbstractTest { then: buildResult.task(':app:cargoBuild').outcome == TaskOutcome.SUCCESS buildResult.task(':library:cargoBuild').outcome == TaskOutcome.SUCCESS + buildResult.task(':app:cargoBuildX86_64').outcome == TaskOutcome.SUCCESS + buildResult.task(':library:cargoBuildX86_64').outcome == TaskOutcome.SUCCESS new File(temporaryFolder.root, "app/build/rustJniLibs/android/x86_64/librust.so").exists() new File(temporaryFolder.root, "library/build/rustJniLibs/android/x86_64/librust.so").exists() + new File(temporaryFolder.root, "app/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/librust.so").exists() + new File(temporaryFolder.root, "library/build/intermediates/merged_jni_libs/debug/mergeDebugJniLibFolders/out/x86_64/librust.so").exists() where: [androidVersion, gradleVersion] << TestVersions.allCandidateTestVersions.entries().collect { [it.key, it.value] } diff --git a/plugin/src/test/groovy/com/nishtahir/CargoEnvironmentTest.groovy b/plugin/src/test/groovy/com/nishtahir/CargoEnvironmentTest.groovy new file mode 100644 index 00000000..6a54bff0 --- /dev/null +++ b/plugin/src/test/groovy/com/nishtahir/CargoEnvironmentTest.groovy @@ -0,0 +1,126 @@ +package com.nishtahir + +import org.gradle.testkit.runner.BuildResult +import spock.lang.IgnoreIf + +@MultiVersionTest +class CargoEnvironmentTest extends AbstractTest { + static final String PREFIX = "RUST_ANDROID_GRADLE_TARGET_X86_64_LINUX_ANDROID_" + + def androidVersion = TestVersions.latestAndroidVersionForCurrentJDK() + + private void writeProject() { + SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) + .withAndroidVersion(androidVersion) + .withKotlinDisabled() + .build() + .writeProject() + + SimpleCargoProject.builder(temporaryFolder.root) + .withTargets(["x86_64"]) + .withChannel("stable") + .build() + .writeProject() + } + + private BuildResult build(Map environment = [:], String... arguments) { + return withGradleVersion(TestVersions.latestSupportedGradleVersionFor(androidVersion).version) + .withProjectDir(temporaryFolder.root) + .withEnvironment(System.getenv() + environment) + .withArguments(arguments.toList() + "--stacktrace") + .build() + } + + private List cargoBuildEnvironment(Map environment = [:], String... arguments) { + def dump = file("cargo-env.txt") + def wrapper = file("rustc-wrapper.sh") + wrapper.text = "#!/bin/sh\nenv >> '${dump.path}'\nexec \"\$@\"\n" + wrapper.setExecutable(true) + + build(environment, *([":app:cargoBuild", "-P${PREFIX}RUSTC_WRAPPER=${wrapper.path}"] + arguments.toList())) + return dump.readLines() + } + + @IgnoreIf({ os.windows }) + def "target properties from every source reach cargo"() { + given: + writeProject() + file("gradle.properties") << "\n${PREFIX}FROM_ROOT_FILE=root\n" + file("app/gradle.properties") << "${PREFIX}FROM_SUBPROJECT_FILE=sub\n" + file("app/build.gradle") << "\next.${PREFIX}FROM_EXT = 'ext'\n" + + when: + def env = cargoBuildEnvironment([("ORG_GRADLE_PROJECT_${PREFIX}FROM_ENV".toString()): "env"], "-P${PREFIX}FROM_CLI=cli") + + then: + env.contains("FROM_CLI=cli") + env.contains("FROM_ENV=env") + env.contains("FROM_ROOT_FILE=root") + env.contains("FROM_SUBPROJECT_FILE=sub") + env.contains("FROM_EXT=ext") + } + + static final String FLAVORS_WITH_LOWER_MIN_SDK = """ + android { + flavorDimensions += "tier" + productFlavors { + high { dimension = "tier" } + low { dimension = "tier"; minSdk = 26 } + mid { dimension = "tier"; minSdk = 28 } + } + } + """.stripIndent() + + @IgnoreIf({ os.windows }) + def "cargo builds with API level #expected for #description"() { + given: + writeProject() + file("app/build.gradle") << config + + when: + def env = cargoBuildEnvironment() + + then: + env.any { it ==~ /RUST_ANDROID_GRADLE_CC=.*x86_64-linux-android${expected}-clang/ } + + where: + description | config | expected + "the lowest variant minSdk" | FLAVORS_WITH_LOWER_MIN_SDK | 26 + "an explicit apiLevel" | "\ncargo { apiLevel = 24 }\n" | 24 + } + + def "#task depends on cargoBuild"() { + given: + writeProject() + file("app/build.gradle") << config + + when: + def result = build(task, "--dry-run") + + then: + result.output.contains(":app:cargoBuild SKIPPED") + + where: + task | config + ":app:testDebugUnitTest" | "" + ":app:mergeLowDebugJniLibFolders" | FLAVORS_WITH_LOWER_MIN_SDK + ":app:testLowDebugUnitTest" | FLAVORS_WITH_LOWER_MIN_SDK + } + + def "desktop libraries are on the unit test classpath"() { + given: + writeProject() + file("app/build.gradle") << """ + tasks.register("printUnitTestClasspath") { + doLast { println("UNIT_TEST_CLASSPATH=" + tasks.getByName("testDebugUnitTest").classpath.files) } + } + """.stripIndent() + + when: + def result = build(":app:printUnitTestClasspath") + + then: + result.output.contains(new File(file("app").canonicalFile, "build/rustJniLibs/desktop").path) + result.output.contains("compileDebugUnitTestJavaWithJavac") + } +} diff --git a/plugin/src/test/groovy/com/nishtahir/CargoTargetTest.groovy b/plugin/src/test/groovy/com/nishtahir/CargoTargetTest.groovy index d6d20827..c2fbd85a 100644 --- a/plugin/src/test/groovy/com/nishtahir/CargoTargetTest.groovy +++ b/plugin/src/test/groovy/com/nishtahir/CargoTargetTest.groovy @@ -11,11 +11,7 @@ class CargoTargetTest extends AbstractTest { def "cargoBuild produces #location for target #target"() { given: def androidVersion = TestVersions.latestAndroidVersionForCurrentJDK() - def ndkVersion = "29.0.14206865" - def ndkVersionMajor = ndkVersion.split('\\.')[0] as int - // Toolchain 1.68 or later versions are not compatible to old NDK prior to r23 - // https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html - def channel = ndkVersionMajor >= 23 ? "stable" : "1.67" + def ndkVersion = "30.0.16248370" SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) .withAndroidVersion(androidVersion) @@ -27,7 +23,7 @@ class CargoTargetTest extends AbstractTest { SimpleCargoProject.builder(temporaryFolder.root) .withTargets([target]) - .withChannel(channel) + .withChannel("stable") .build() .writeProject() @@ -54,10 +50,8 @@ class CargoTargetTest extends AbstractTest { // Sadly, cross-compiling to macOS targets fails at this time: see // https://github.com/rust-lang/rust/issues/84984. // ["darwin", "desktop/darwin/librust.dylib"], - // And so does cross-compiling from macOS to Linux targets. - // ["linux-x86-64", "desktop/linux-x86-64/librust.so"], ["arm64", "android/arm64-v8a/librust.so"], ["x86_64", "android/x86_64/librust.so"], - ] + ] + (System.getProperty("os.name") == "Linux" ? [["linux-x86-64", "desktop/linux-x86-64/librust.so"]] : []) } } diff --git a/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy b/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy index a18c97e1..e35c0f6b 100644 --- a/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy +++ b/plugin/src/test/groovy/com/nishtahir/NdkVersionTest.groovy @@ -13,10 +13,6 @@ class NdkVersionTest extends AbstractTest { def androidVersion = TestVersions.latestAndroidVersionForCurrentJDK() def target = "x86_64" def location = "android/x86_64/librust.so" - def ndkVersionMajor = ndkVersion.split('\\.')[0] as int - // Toolchain 1.68 or later versions are not compatible to old NDK prior to r23 - // https://blog.rust-lang.org/2023/01/09/android-ndk-update-r25.html - def channel = ndkVersionMajor >= 23 ? "stable" : "1.67" SimpleAndroidApp.builder(temporaryFolder.root, cacheDir) .withAndroidVersion(androidVersion) @@ -28,7 +24,7 @@ class NdkVersionTest extends AbstractTest { SimpleCargoProject.builder(temporaryFolder.root) .withTargets([target]) - .withChannel(channel) + .withChannel("stable") .build() .writeProject() @@ -63,8 +59,8 @@ class NdkVersionTest extends AbstractTest { // Partial list of NDK versions supported by Github Actions, per // https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2604-Readme.md#android "27.3.13750724", - "28.2.13676358", "29.0.14206865", + "30.0.16248370", ] } } diff --git a/plugin/src/test/groovy/com/nishtahir/SimpleAndroidApp.groovy b/plugin/src/test/groovy/com/nishtahir/SimpleAndroidApp.groovy index 0e01954f..ec34ee08 100644 --- a/plugin/src/test/groovy/com/nishtahir/SimpleAndroidApp.groovy +++ b/plugin/src/test/groovy/com/nishtahir/SimpleAndroidApp.groovy @@ -1,9 +1,7 @@ package com.nishtahir import org.gradle.api.GradleException -import org.gradle.util.VersionNumber - -import static com.nishtahir.Versions.android +import java.lang.module.ModuleDescriptor.Version as VersionNumber class SimpleAndroidApp { final File projectDir @@ -97,7 +95,7 @@ class SimpleAndroidApp { """.stripIndent() file("${app}/build.gradle") << subprojectConfiguration("com.android.application", appPackage) << """ - android.defaultConfig.applicationId "org.gradle.android.test.app" + android.defaultConfig.applicationId = "org.gradle.android.test.app" """.stripIndent() << activityDependency() << """ dependencies { @@ -139,15 +137,14 @@ class SimpleAndroidApp { android { ${maybeNdkVersion} - compileSdkVersion 30 - namespace '${namespace}' + compileSdk = 36 + namespace = '${namespace}' defaultConfig { - minSdkVersion 30 - targetSdkVersion 30 - - lintOptions { - checkReleaseBuilds false - } + minSdk = 30 + targetSdk = 36 + } + lint { + checkReleaseBuilds = false } } """.stripIndent() @@ -155,7 +152,7 @@ class SimpleAndroidApp { private String getMaybeNdkVersion() { if (ndkVersion != null) { - return """ndkVersion '${ndkVersion}'""" + return """ndkVersion = '${ndkVersion}'""" } else { return "" } @@ -303,10 +300,6 @@ class SimpleAndroidApp { return this } - Builder withAndroidVersion(String androidVersion) { - return withAndroidVersion(android(androidVersion)) - } - Builder withNdkVersion(VersionNumber ndkVersion) { this.ndkVersion = ndkVersion return this @@ -327,9 +320,7 @@ class SimpleAndroidApp { } SimpleAndroidApp build() { - if (ndkVersion == null && androidVersion >= android("3.4.0")) { - ndkVersion = VersionNumber.parse("29.0.14206865") - } + ndkVersion = ndkVersion ?: VersionNumber.parse("30.0.16248370") return new SimpleAndroidApp(projectDir, cacheDir, androidVersion, ndkVersion, kotlinVersion, kotlinEnabled, kaptWorkersEnabled) } } diff --git a/plugin/src/test/groovy/com/nishtahir/TestVersions.groovy b/plugin/src/test/groovy/com/nishtahir/TestVersions.groovy index cdd6c8da..6d634db2 100644 --- a/plugin/src/test/groovy/com/nishtahir/TestVersions.groovy +++ b/plugin/src/test/groovy/com/nishtahir/TestVersions.groovy @@ -3,7 +3,7 @@ package com.nishtahir import com.google.common.collect.ImmutableMultimap import com.google.common.collect.Multimap import org.gradle.util.GradleVersion -import org.gradle.util.VersionNumber +import java.lang.module.ModuleDescriptor.Version as VersionNumber class TestVersions { @@ -17,32 +17,10 @@ class TestVersions { } static VersionNumber latestAndroidVersionForCurrentJDK() { - String currentJDKVersion = System.getProperty("java.version"); - if (currentJDKVersion.startsWith("1.")) { - return allCandidateTestVersions.keySet().findAll {it < VersionNumber.parse("7.0.0-alpha01")}.max() - } return allCandidateTestVersions.keySet().max() } - static GradleVersion latestGradleVersion() { - return allCandidateTestVersions.values().max() - } - - static GradleVersion latestSupportedGradleVersionFor(String androidVersion) { - return latestSupportedGradleVersionFor(VersionNumber.parse(androidVersion)) - } - static GradleVersion latestSupportedGradleVersionFor(VersionNumber androidVersion) { - return allCandidateTestVersions.asMap().find {it.key.major == androidVersion.major && it.key.minor == androidVersion.minor }?.value?.max() - } - - static VersionNumber getLatestVersionForAndroid(String version) { - VersionNumber versionNumber = VersionNumber.parse(version) - return allCandidateTestVersions.keySet().findAll { it.major == versionNumber.major && it.minor == versionNumber.minor }?.max() - } - - static List getLatestAndroidVersions() { - def minorVersions = allCandidateTestVersions.keySet().collect { "${it.major}.${it.minor}" } - return minorVersions.collect { getLatestVersionForAndroid(it) } + return allCandidateTestVersions.get(androidVersion).max() } } diff --git a/plugin/src/main/groovy/com/nishtahir/Versions.groovy b/plugin/src/test/groovy/com/nishtahir/Versions.groovy similarity index 59% rename from plugin/src/main/groovy/com/nishtahir/Versions.groovy rename to plugin/src/test/groovy/com/nishtahir/Versions.groovy index c8143bc4..85ee57a6 100644 --- a/plugin/src/main/groovy/com/nishtahir/Versions.groovy +++ b/plugin/src/test/groovy/com/nishtahir/Versions.groovy @@ -1,19 +1,16 @@ package com.nishtahir import com.google.common.collect.ImmutableMultimap -import com.google.common.collect.ImmutableSortedSet import com.google.common.collect.Multimap import groovy.json.JsonSlurper import groovy.transform.CompileStatic import groovy.transform.TypeCheckingMode import org.gradle.util.GradleVersion -import org.gradle.util.VersionNumber +import java.lang.module.ModuleDescriptor.Version as VersionNumber @CompileStatic(TypeCheckingMode.SKIP) class Versions { static final VersionNumber PLUGIN_VERSION; - static final Set SUPPORTED_GRADLE_VERSIONS - static final Set SUPPORTED_ANDROID_VERSIONS static final Multimap SUPPORTED_VERSIONS_MATRIX static { @@ -24,11 +21,7 @@ class Versions { versions.supportedVersions.each { String androidVersion, List gradleVersions -> builder.putAll(android(androidVersion), gradleVersions.collect { gradle(it) }) } - def matrix = builder.build() - - SUPPORTED_VERSIONS_MATRIX = matrix - SUPPORTED_ANDROID_VERSIONS = ImmutableSortedSet.copyOf(matrix.keySet()) - SUPPORTED_GRADLE_VERSIONS = ImmutableSortedSet.copyOf(matrix.values()) + SUPPORTED_VERSIONS_MATRIX = builder.build() } static VersionNumber android(String version) { @@ -39,13 +32,7 @@ class Versions { GradleVersion.version(version) } - static VersionNumber earliestMaybeSupportedAndroidVersion() { - VersionNumber earliestSupported = SUPPORTED_ANDROID_VERSIONS.min() - // "alpha" is lower than null - return new VersionNumber(earliestSupported.major, earliestSupported.minor, 0, "alpha") - } - static VersionNumber latestAndroidVersion() { - return SUPPORTED_ANDROID_VERSIONS.max() + return SUPPORTED_VERSIONS_MATRIX.keySet().max() } } diff --git a/samples/app/build.gradle b/samples/app/build.gradle index 66351263..f4d7304c 100644 --- a/samples/app/build.gradle +++ b/samples/app/build.gradle @@ -1,9 +1,9 @@ buildscript { - ext.agp_version = '8.2.0' + ext.agp_version = '9.5.1' repositories { google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } dependencies { @@ -16,24 +16,18 @@ apply plugin: 'com.android.application' apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { - compileSdkVersion 30 - ndkVersion "29.0.14206865" + compileSdk = 36 + ndkVersion = "30.0.16248370" namespace = 'com.nishtahir.androidrust' defaultConfig { - applicationId "com.nishtahir.androidrust" - minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } + applicationId = "com.nishtahir.androidrust" + minSdk = 21 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } } @@ -56,21 +50,3 @@ dependencies { implementation 'com.android.support.constraint:constraint-layout:1.0.2' testImplementation 'junit:junit:4.12' } - -// Java 17: Required for Gradle 8.5+ and AGP 8.x -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -afterEvaluate { - // The `cargoBuild` task isn't available until after evaluation. - android.applicationVariants.all { variant -> - def productFlavor = "" - variant.productFlavors.each { - productFlavor += "${it.name.capitalize()}" - } - def buildType = "${variant.buildType.name.capitalize()}" - tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"]) - } -} diff --git a/samples/library/build.gradle b/samples/library/build.gradle index 672896ca..f5bf5706 100644 --- a/samples/library/build.gradle +++ b/samples/library/build.gradle @@ -1,9 +1,9 @@ buildscript { - ext.agp_version = '8.2.0' + ext.agp_version = '9.5.1' repositories { google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } dependencies { @@ -16,24 +16,18 @@ apply plugin: 'com.android.library' apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { - compileSdkVersion 30 - ndkVersion "29.0.14206865" + compileSdk = 36 + ndkVersion = "30.0.16248370" namespace = 'com.nishtahir.library' defaultConfig { - minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" + minSdk = 21 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } + testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } } @@ -65,21 +59,3 @@ dependencies { implementation 'com.android.support:appcompat-v7:27.1.1' testImplementation 'junit:junit:4.12' } - -// Java 17: Required for Gradle 8.5+ and AGP 8.x -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -afterEvaluate { - // The `cargoBuild` task isn't available until after evaluation. - android.libraryVariants.all { variant -> - def productFlavor = "" - variant.productFlavors.each { - productFlavor += "${it.name.capitalize()}" - } - def buildType = "${variant.buildType.name.capitalize()}" - tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"]) - } -} diff --git a/samples/library/proguard-rules.pro b/samples/library/proguard-rules.pro deleted file mode 100644 index 9a62cf11..00000000 --- a/samples/library/proguard-rules.pro +++ /dev/null @@ -1,25 +0,0 @@ -# Add project specific ProGuard rules here. -# By default, the flags in this file are appended to flags specified -# in /Users/nishtahir/Library/Android/sdk/tools/proguard/proguard-android.txt -# You can edit the include path and order by changing the proguardFiles -# directive in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# Add any project specific keep options here: - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/samples/unittest/build.gradle b/samples/unittest/build.gradle index 932af296..2d1c92e8 100644 --- a/samples/unittest/build.gradle +++ b/samples/unittest/build.gradle @@ -1,9 +1,9 @@ buildscript { - ext.agp_version = '8.2.0' + ext.agp_version = '9.5.1' repositories { google() maven { - url "https://plugins.gradle.org/m2/" + url = "https://plugins.gradle.org/m2/" } } dependencies { @@ -16,33 +16,23 @@ apply plugin: 'com.android.application' apply plugin: 'org.mozilla.rust-android-gradle.rust-android' android { - compileSdkVersion 30 + compileSdk = 36 namespace = 'com.nishtahir.androidrust' defaultConfig { - applicationId "com.nishtahir.androidrust" - minSdkVersion 21 - targetSdkVersion 30 - versionCode 1 - versionName "1.0" - testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" - } - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } - ndkVersion "29.0.14206865" - sourceSets { - test.resources.srcDirs += "$buildDir/rustJniLibs/desktop" + applicationId = "com.nishtahir.androidrust" + minSdk = 21 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner" } + ndkVersion = "30.0.16248370" } cargo { module = "../rust" - targets = ["x86_64", "linux-x86-64"] // "x86", "x86_64", "arm64"] targets = ["arm64", "darwin-aarch64"] libname = "rust" } @@ -79,7 +69,7 @@ dependencies { }) implementation 'com.android.support:appcompat-v7:27.1.1' implementation 'com.android.support.constraint:constraint-layout:1.0.2' - testImplementation 'junit:junit:4.12' + testImplementation 'junit:junit:4.13.2' // For reasons unknown, resolving the jnaForTest configuration directly // trips a nasty issue with the Android-Gradle plugin 3.2.1, like `Cannot @@ -89,30 +79,5 @@ dependencies { // causing it to be resolved. Cloning first dissociates the configuration, // avoiding other configurations from being resolved. Tricky! testImplementation files(configurations.jnaForTest.copyRecursive().files) - // testImplementation "androidx.test.ext:junit:$versions.androidx_junit" - testImplementation "org.robolectric:robolectric:4.14.1" -} - -// Java 17: Required for Gradle 8.5+ and AGP 8.x -java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 -} - -afterEvaluate { - // The `cargoBuild` task isn't available until after evaluation. - android.applicationVariants.all { variant -> - def productFlavor = "" - variant.productFlavors.each { - productFlavor += "${it.name.capitalize()}" - } - def buildType = "${variant.buildType.name.capitalize()}" - tasks["generate${productFlavor}${buildType}Assets"].dependsOn(tasks["cargoBuild"]) - - // Don't merge the jni lib folders until after the Rust libraries have been built. - tasks["merge${productFlavor}${buildType}JniLibFolders"].dependsOn(tasks["cargoBuild"]) - - // For unit tests. - tasks["process${productFlavor}${buildType}UnitTestJavaRes"].dependsOn(tasks["cargoBuild"]) - } + testImplementation "org.robolectric:robolectric:4.17" } diff --git a/samples/unittest/gradle.properties b/samples/unittest/gradle.properties deleted file mode 100644 index 5bac8ac5..00000000 --- a/samples/unittest/gradle.properties +++ /dev/null @@ -1 +0,0 @@ -android.useAndroidX=true diff --git a/samples/unittest/gradle/wrapper/gradle-wrapper.jar b/samples/unittest/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index f3d88b1c..00000000 Binary files a/samples/unittest/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/samples/unittest/gradle/wrapper/gradle-wrapper.properties b/samples/unittest/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 1b16c34a..00000000 --- a/samples/unittest/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,5 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-bin.zip -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/samples/unittest/gradlew b/samples/unittest/gradlew deleted file mode 100755 index 2fe81a7d..00000000 --- a/samples/unittest/gradlew +++ /dev/null @@ -1,183 +0,0 @@ -#!/usr/bin/env sh - -# -# Copyright 2015 the original author or 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 UN*X -## -############################################################################## - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >/dev/null -APP_HOME="`pwd -P`" -cd "$SAVED" >/dev/null - -APP_NAME="Gradle" -APP_BASE_NAME=`basename "$0"` - -# 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 "$*" -} - -die () { - echo - echo "$*" - echo - exit 1 -} - -# 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 - ;; - 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" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then - MAX_FD_LIMIT=`ulimit -H -n` - if [ $? -eq 0 ] ; then - if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then - MAX_FD="$MAX_FD_LIMIT" - fi - ulimit -n $MAX_FD - if [ $? -ne 0 ] ; then - warn "Could not set maximum file descriptor limit: $MAX_FD" - fi - else - warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" - fi -fi - -# For Darwin, add options to specify how the application appears in the dock -if $darwin; then - GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" -fi - -# For Cygwin or MSYS, switch paths to Windows format before running java -if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then - APP_HOME=`cygpath --path --mixed "$APP_HOME"` - CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - JAVACMD=`cygpath --unix "$JAVACMD"` - - # We build the pattern for arguments to be converted via cygpath - ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` - SEP="" - for dir in $ROOTDIRSRAW ; do - ROOTDIRS="$ROOTDIRS$SEP$dir" - SEP="|" - done - OURCYGPATTERN="(^($ROOTDIRS))" - # Add a user-defined pattern to the cygpath arguments - if [ "$GRADLE_CYGPATTERN" != "" ] ; then - OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" - fi - # Now convert the arguments - kludge to limit ourselves to /bin/sh - i=0 - for arg in "$@" ; do - CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` - CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option - - if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition - eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` - else - eval `echo args$i`="\"$arg\"" - fi - i=`expr $i + 1` - done - case $i in - 0) set -- ;; - 1) set -- "$args0" ;; - 2) set -- "$args0" "$args1" ;; - 3) set -- "$args0" "$args1" "$args2" ;; - 4) set -- "$args0" "$args1" "$args2" "$args3" ;; - 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; - esac -fi - -# Escape application args -save () { - for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done - echo " " -} -APP_ARGS=`save "$@"` - -# Collect all arguments for the java command, following the shell quoting and substitution rules -eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" - -exec "$JAVACMD" "$@" diff --git a/samples/unittest/gradlew.bat b/samples/unittest/gradlew.bat deleted file mode 100644 index 24467a14..00000000 --- a/samples/unittest/gradlew.bat +++ /dev/null @@ -1,100 +0,0 @@ -@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=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@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%" == "0" goto init - -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 init - -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 - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -: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 %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega