diff --git a/.github/actions/setup-build-and-test-w-make-impl/action.yml b/.github/actions/setup-build-and-test-w-make-impl/action.yml index 34d7e37ef8..c4904a93ee 100644 --- a/.github/actions/setup-build-and-test-w-make-impl/action.yml +++ b/.github/actions/setup-build-and-test-w-make-impl/action.yml @@ -55,7 +55,7 @@ runs: shell: bash - name: Configure run: |- - ../repo/configure --enable-protobuf --with-android-sdk="$(pwd)/../sdk" ${{ inputs.configure_extra }} + ../repo/configure --enable-protobuf --with-android-sdk="$(pwd)/../sdk" --with-r8="$(pwd)/../r8.jar" ${{ inputs.configure_extra }} working-directory: build shell: bash - name: Build diff --git a/.github/actions/test-build-setup/action.yml b/.github/actions/test-build-setup/action.yml index b2aba46d7c..e25b850e96 100644 --- a/.github/actions/test-build-setup/action.yml +++ b/.github/actions/test-build-setup/action.yml @@ -18,12 +18,12 @@ runs: path: sdk.tar.zstd - name: Check/Install (SDK) run: |- - if [ -e sdk/build-tools/29.0.2/dx ] ; then echo "Found SDK." ; exit 0 ; fi + if [ -e sdk/build-tools/29.0.2/aapt2 ] ; then echo "Found SDK." ; exit 0 ; fi - # Check whether cache file exists, then check dx again. + # Check whether cache file exists, then check aapt2 again. if [ -f "sdk.tar.zstd" ] ; then zstd --decompress --stdout sdk.tar.zstd | tar xf - - if [ -e sdk/build-tools/29.0.2/dx ] ; then echo "Unpacked SDK." ; exit 0 ; fi + if [ -e sdk/build-tools/29.0.2/aapt2 ] ; then echo "Unpacked SDK." ; exit 0 ; fi fi # Download. @@ -42,3 +42,19 @@ runs: rm -rf sdk/emulator 2>/dev/null tar cf - sdk | zstd -T0 -9 > sdk.tar.zstd shell: bash + # d8 is pinned to an R8 release instead of taken from the SDK: the build-tools + # d8 tracks the SDK release train rather than the Android Gradle Plugin, and + # lags it by years. Keep this version aligned with the AGP release Redex is + # expected to consume the output of. + - name: Cache R8 + uses: actions/cache@v5 + with: + key: v1-r8-8.8.34 + path: r8.jar + - name: Check/Install (R8) + run: |- + if [ -f r8.jar ] ; then echo "Found R8." ; exit 0 ; fi + + echo "R8 missing, downloading..." + wget -O r8.jar https://maven.google.com/com/android/tools/r8/8.8.34/r8-8.8.34.jar + shell: bash diff --git a/configure.ac b/configure.ac index ebe093436b..f6a17b36c3 100644 --- a/configure.ac +++ b/configure.ac @@ -123,21 +123,30 @@ AC_ARG_WITH([android-sdk], [AC_PATH_PROG([PROTOC], [protoc], [no])]) ] ) -# Look for dx & android.jar. +# The R8 jar is pinned rather than taken from the SDK: the d8 bundled with the +# Android build-tools tracks the SDK release train, not the Android Gradle +# Plugin, and its dex output is years behind the d8 that ships in AGP. +AC_ARG_WITH([r8], + [AS_HELP_STRING([--with-r8=/path/to/r8.jar], + [Location of the R8 jar, which provides d8, for testing.])], + [R8_JAR="$withval"], + [] +) +# Look for java, the R8 jar & android.jar. AS_IF([test "x$NO_ANDROID_HOME" = "xno"], [], [ - # Do not assume a totally new SDK. Try platform 29. - AC_PATH_PROG( - DX, - dx, - no, - "$ANDROID_HOME/build-tools/29.0.2:$PATH" - ) - AS_IF([test "x$DX" = "xno"], - [AC_MSG_ERROR([--with-android-sdk option was specified but does not seem to point at a valid Android SDK installation])] + AC_PATH_PROG([JAVA], [java], [no]) + AS_IF([test "x$JAVA" = "xno"], + [AC_MSG_ERROR([java is required to run d8])] [] ) + AC_CHECK_FILE( + "$R8_JAR", + [AC_SUBST(R8_JAR,"$R8_JAR")], + [AC_MSG_ERROR([--with-r8 must point at an R8 jar providing com.android.tools.r8.D8])] + ) + # Do not assume a totally new SDK. Try platform 29. AC_CHECK_FILE( "$ANDROID_HOME/platforms/android-29/android.jar", [ diff --git a/test/integ/Makefile.am b/test/integ/Makefile.am index 8bbf4d7e4f..ac1c16ad6f 100644 --- a/test/integ/Makefile.am +++ b/test/integ/Makefile.am @@ -1,10 +1,12 @@ include $(top_srcdir)/Makefile.inc include $(top_srcdir)/test/Makefile.inc -DX = @DX@ +JAVA = @JAVA@ +R8_JAR = @R8_JAR@ ANDROID_SDK = @ANDROID_SDK@ ANDROID_PLATFORM_VERSION = @ANDROID_PLATFORM_VERSION@ +ANDROID_JAR = $(ANDROID_SDK)/platforms/$(ANDROID_PLATFORM_VERSION)/android.jar AM_CXXFLAGS = --std=gnu++20 AM_CPPFLAGS = $(COMMON_INCLUDES) $(COMMON_TEST_INCLUDES) @@ -215,8 +217,10 @@ EXTRA_uses_app_module_annotation_test_DEPENDENCIES = uses_app_module_annotation- verifier_artifacts_test_SOURCES = VerifierTest.cpp EXTRA_verifier_artifacts_test_DEPENDENCIES = verifier_artifacts_test-class.dex -# Note: Should switch to d8, instead. -javac_source_target = -source 8 -target 8 +javac_source_target = -source 11 -target 11 + +# Matches the platform the tests are compiled and run against. +d8_min_api = 29 define create_jar mkdir -p $@.tmp @@ -226,8 +230,13 @@ endef SUFFIXES = .dex +# d8 only writes into a directory or a zip, always naming the result +# classes.dex, so the single-dex output has to be moved into place. .jar.dex: - $(DX) --dex --output=$@ $^ + mkdir -p $@.tmp + $(JAVA) -cp $(R8_JAR) com.android.tools.r8.D8 --min-api $(d8_min_api) \ + --lib $(ANDROID_JAR) --output $@.tmp $^ + mv $@.tmp/classes.dex $@ app_module_usage_test-class.jar: AppModuleUsageClass.java $(create_jar)