From 62d9defefba8b549e0cbc8901c72ef29ea797c68 Mon Sep 17 00:00:00 2001 From: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:25:36 +0000 Subject: [PATCH 1/4] CI: Robolectric's jars through Gradle; the bump on the latest main Android's unit tests fail on main (runs 411, 413, 417, 419, 424): each Robolectric test fails in MavenArtifactFetcher with an IOException. Robolectric downloads its Android framework jars (about 200 MB each) during the tests, and Maven Central refuses some downloads with HTTP 429 (its rate limit). Now Gradle downloads the two jars that the tests use (SDK 28 and SDK 35), with its retries and its cache, and Robolectric runs offline from their directory. -ProbolectricRepoUrl= still makes Robolectric download them itself from that mirror. Gradle tries a refused download again, up to 6 times (gradle.properties). The D-Modem bump checked out the commit that its event names. A run that waited for the run before it therefore built on an old main, and its pull request (#103) conflicted with the one that the earlier run merged (#102). Now it checks out main as it is when the run starts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRSYSk1rgeTZ9ZWMcZL Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> --- .github/workflows/d-modem-bump.yml | 3 +++ app/build.gradle.kts | 33 +++++++++++++++++++++++++++--- gradle.properties | 4 ++++ 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/.github/workflows/d-modem-bump.yml b/.github/workflows/d-modem-bump.yml index bb02989..a9b43a3 100644 --- a/.github/workflows/d-modem-bump.yml +++ b/.github/workflows/d-modem-bump.yml @@ -51,9 +51,12 @@ jobs: exit 1 fi + # main as it is now, not the commit the event names: a run that waited for the one before it + # (concurrency) builds on the main that the earlier run merged into, and does not conflict with it - uses: actions/checkout@v6 with: token: ${{ secrets.DMODEM_BUMP_TOKEN }} + ref: main fetch-depth: 0 # only the D-Modem submodule (proot stays where it is) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 7aa3d7a..60577c7 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -201,10 +201,37 @@ val buildHostSsh = tasks.register("buildHostSsh") { ) } -// Robolectric fetches its Android framework jars itself: -ProbolectricRepoUrl= to fetch them elsewhere +// Robolectric's Android framework jars (android-all-instrumented, about 200 MB each), one for each SDK +// that a test's @Config names (app/src/test). Gradle downloads them, with its retries and its cache +// (CI's setup-gradle keeps the cache). Robolectric then runs offline from their directory. +// Without this, Robolectric downloads them itself during the tests, and Maven Central's rate limit +// (HTTP 429) makes each Robolectric test fail. +// A new SDK in a test's @Config: add its jar here. Robolectric's DefaultSdkProvider gives the version +// for its release (libs.versions.toml): "-robolectric--i". +// -ProbolectricRepoUrl=: Robolectric downloads them itself from that mirror instead. +val robolectricJars = configurations.create("robolectricJars") { + isTransitive = false + isCanBeConsumed = false +} +dependencies { + // SDK 28 (Android 9) and SDK 35 (Android 15), Robolectric 4.17's jars + robolectricJars("org.robolectric:android-all-instrumented:9-robolectric-4913185-2-i7") + robolectricJars("org.robolectric:android-all-instrumented:15-robolectric-13954326-i7") +} +val robolectricJarsDir = layout.buildDirectory.dir("robolectric-jars") +val syncRobolectricJars = tasks.register("syncRobolectricJars") { + description = "Copies Robolectric's Android framework jars to one directory, for its offline mode" + from(robolectricJars) + into(robolectricJarsDir) +} +val robolectricRepoUrl = providers.gradleProperty("robolectricRepoUrl").orNull tasks.withType().configureEach { - providers.gradleProperty("robolectricRepoUrl").orNull?.let { - systemProperty("robolectric.dependency.repo.url", it) + if (robolectricRepoUrl != null) { + systemProperty("robolectric.dependency.repo.url", robolectricRepoUrl) + } else { + dependsOn(syncRobolectricJars) + systemProperty("robolectric.offline", "true") + systemProperty("robolectric.dependency.dir", robolectricJarsDir.get().asFile.path) } // the SSH client's JNI library built for the host (native-ssh), for the SSH tests dependsOn(buildHostSsh) diff --git a/gradle.properties b/gradle.properties index 5299c5f..a63faaa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,3 +3,7 @@ org.gradle.caching=true android.useAndroidX=true android.nonTransitiveRClass=true kotlin.code.style=official +# A download that Maven Central refuses for a short time (HTTP 429, its rate limit): Gradle tries it again, +# up to 6 times, waiting 2 s, then 4 s, and so on (Robolectric's large jars: app/build.gradle.kts) +systemProp.org.gradle.internal.repository.max.retries=6 +systemProp.org.gradle.internal.repository.initial.backoff=2000 From b0f0d53045ec80772f521dcdbee67d4f829a584a Mon Sep 17 00:00:00 2001 From: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:27:41 +0000 Subject: [PATCH 2/4] CI: cache the downloads (Robolectric's jars, the SDK packages) Robolectric's Android framework jars (about 200 MB each) get their own cache entry, keyed on their versions. The build job saves it also when a test fails. setup-gradle's cache does not keep them a second time. .github/actions/android-sdk: sdkmanager install, with the packages that the runner image does not have (CMake each run until now, and the emulator's system image) cached, keyed on the image and the package list. The three Android jobs use it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRSYSk1rgeTZ9ZWMcZL Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> --- .github/actions/android-sdk/action.yml | 62 ++++++++++++++++++++++++++ .github/workflows/android.yml | 58 ++++++++++++++++++------ 2 files changed, 107 insertions(+), 13 deletions(-) create mode 100644 .github/actions/android-sdk/action.yml diff --git a/.github/actions/android-sdk/action.yml b/.github/actions/android-sdk/action.yml new file mode 100644 index 0000000..11550a9 --- /dev/null +++ b/.github/actions/android-sdk/action.yml @@ -0,0 +1,62 @@ +# sdkmanager install with its downloads cached (actions/cache): the +# packages that the runner image does not have (for example CMake, or the +# emulator's system image) are kept in the cache, keyed on the runner image +# (ImageOS, ImageVersion) and the package list. On a hit, sdkmanager finds +# them installed and downloads nothing. On a miss, sdkmanager downloads +# them (it tries again up to 3 times), and the cache is saved for the next +# run. The packages that the image has are not cached. +name: Android SDK packages +description: sdkmanager install, cached +inputs: + packages: + description: the sdkmanager packages (spaces or newlines between), for example "cmake;3.31.6" + required: true +runs: + using: composite + steps: + # the key, and the directories of the packages that the image does not have + # ("cmake;3.31.6" is $ANDROID_HOME/cmake/3.31.6) + - id: key + shell: bash + env: + PKGS: ${{ inputs.packages }} + run: | + pkgs=$(printf '%s\n' $PKGS | sort -u | tr '\n' ' ') + echo "pkgs=$pkgs" >> "$GITHUB_OUTPUT" + dirs= + for p in $pkgs; do + d="$ANDROID_HOME/${p//;//}" + [ -e "$d" ] || dirs="$dirs$d"$'\n' + done + { + echo 'dirs<> "$GITHUB_OUTPUT" + [ -n "$dirs" ] && echo "any=true" >> "$GITHUB_OUTPUT" || echo "any=false" >> "$GITHUB_OUTPUT" + # (ImageOS, ImageVersion: the runner's environment, not the env context) + echo "key=sdk-${ImageOS:-none}-$RUNNER_ARCH-${ImageVersion:-none}-$(printf '%s' "$pkgs" | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" + + - id: restore + if: steps.key.outputs.any == 'true' + uses: actions/cache/restore@v5 + with: + path: ${{ steps.key.outputs.dirs }} + key: ${{ steps.key.outputs.key }} + + - id: install + shell: bash + env: + PKGS: ${{ steps.key.outputs.pkgs }} + run: | + set -euo pipefail + sdk="$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" + yes | "$sdk" --licenses > /dev/null || true + for i in 1 2 3; do "$sdk" $PKGS && break; [ $i = 3 ] && exit 1; sleep $((i * 10)); done + + - if: steps.key.outputs.any == 'true' && steps.restore.outputs.cache-hit != 'true' + uses: actions/cache/save@v5 + continue-on-error: true + with: + path: ${{ steps.key.outputs.dirs }} + key: ${{ steps.key.outputs.key }} diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 6ed78a1..45c6d13 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -12,7 +12,12 @@ # pull request is tried with). # # Packages: apt's downloads are cached (.github/actions/apt), keyed on -# the runner image and the package list. +# the runner image and the package list. The Android SDK packages that +# the image does not have (CMake, the emulator's system image) are cached +# the same way (.github/actions/android-sdk). Robolectric's Android +# framework jars have their own cache entry, keyed on their versions +# (app/build.gradle.kts), so the unit tests do not download them from +# Maven Central. # # D-Modem is a public submodule: the checkout needs no token. # @@ -77,12 +82,26 @@ jobs: java-version: "21" - uses: gradle/actions/setup-gradle@v5 + with: + # (Robolectric's jars: their own cache, below) + gradle-home-cache-excludes: caches/modules-2/files-2.1/org.robolectric + + # Robolectric's Android framework jars (about 200 MB each, app/build.gradle.kts), in Gradle's + # cache: their own cache entry, keyed on their versions, so a run does not download them + # from Maven Central (its rate limit, HTTP 429) + - name: Robolectric's jars, key + id: robolectric + run: echo "key=robolectric-$(grep -h 'android-all-instrumented:' app/build.gradle.kts | sort | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" + - id: robolectric-restore + uses: actions/cache/restore@v5 + with: + path: ~/.gradle/caches/modules-2/files-2.1/org.robolectric + key: ${{ steps.robolectric.outputs.key }} - name: SDK packages - run: | - yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null - "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \ - "ndk;$NDK_VERSION" "cmake;$CMAKE_VERSION" "platforms;android-37.0" + uses: ./.github/actions/android-sdk + with: + packages: ndk;${{ env.NDK_VERSION }} cmake;${{ env.CMAKE_VERSION }} platforms;android-37.0 - name: OpenSSH, PuTTY, mksh (the interop tests), gawk (proot's build) uses: ./.github/actions/apt @@ -109,6 +128,20 @@ jobs: ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }} ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }} + # (saved also when a test fails: the jars that Gradle downloaded are good) + - name: Robolectric's jars, downloaded + id: robolectric-got + if: ${{ !cancelled() && steps.robolectric-restore.outputs.cache-hit != 'true' }} + run: | + d=~/.gradle/caches/modules-2/files-2.1/org.robolectric/android-all-instrumented + [ "$(find "$d" -name '*.jar' 2>/dev/null | wc -l)" -ge 2 ] && echo "save=true" >> "$GITHUB_OUTPUT" || true + - if: ${{ !cancelled() && steps.robolectric-got.outputs.save == 'true' }} + uses: actions/cache/save@v5 + continue-on-error: true + with: + path: ~/.gradle/caches/modules-2/files-2.1/org.robolectric + key: ${{ steps.robolectric.outputs.key }} + - name: The APK's signer if: ${{ !cancelled() && hashFiles('app/build/outputs/apk/debug/app-debug.apk') != '' }} run: | @@ -153,10 +186,9 @@ jobs: - uses: gradle/actions/setup-gradle@v5 - name: SDK packages - run: | - yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null - "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \ - "ndk;$NDK_VERSION" "cmake;$CMAKE_VERSION" "platforms;android-37.0" + uses: ./.github/actions/android-sdk + with: + packages: ndk;${{ env.NDK_VERSION }} cmake;${{ env.CMAKE_VERSION }} platforms;android-37.0 - name: gawk (proot's build) uses: ./.github/actions/apt @@ -294,10 +326,10 @@ jobs: sudo udevadm trigger --name-match=kvm - name: SDK packages - run: | - yes | "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" --licenses > /dev/null - "$ANDROID_HOME/cmdline-tools/latest/bin/sdkmanager" \ - "ndk;$NDK_VERSION" "cmake;$CMAKE_VERSION" "platforms;android-37.0" + uses: ./.github/actions/android-sdk + with: + # (the emulator's system image too: the emulator runner finds it installed) + packages: ndk;${{ env.NDK_VERSION }} cmake;${{ env.CMAKE_VERSION }} platforms;android-37.0 system-images;android-35;google_apis;x86_64 - name: Instrumented tests uses: reactivecircus/android-emulator-runner@v2 From 21cb0e54123b206c1559c1d6b19fefa4a1912f1d Mon Sep 17 00:00:00 2001 From: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:38:26 +0000 Subject: [PATCH 3/4] CI: Gradle downloads from Google's mirror of Maven Central The build job failed on this pull request: Maven Central refused nativeruntime-dist-compat-1.0.19.jar (Robolectric's) with HTTP 429, also after Gradle's retries. The cause: setup-gradle's cache did not keep org.robolectric's files (gradle-home-cache-excludes), and the Robolectric cache entry was empty. - MAVEN_CENTRAL_MIRROR (android.yml, apple.yml): Google's mirror of Maven Central. Gradle tries it before Maven Central (settings.gradle.kts). Without the variable, the repositories are as before. - setup-gradle keeps all of Gradle's cache again. - The Robolectric cache entry holds all of org.robolectric's files. Its key is Robolectric's version, its jars' versions and the list of files. A run that downloads more files saves a new entry. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRSYSk1rgeTZ9ZWMcZL Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> --- .github/workflows/android.yml | 40 +++++++++++++++++++++++------------ .github/workflows/apple.yml | 5 +++++ settings.gradle.kts | 6 ++++++ 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/.github/workflows/android.yml b/.github/workflows/android.yml index 45c6d13..dfaf8d3 100644 --- a/.github/workflows/android.yml +++ b/.github/workflows/android.yml @@ -14,10 +14,11 @@ # Packages: apt's downloads are cached (.github/actions/apt), keyed on # the runner image and the package list. The Android SDK packages that # the image does not have (CMake, the emulator's system image) are cached -# the same way (.github/actions/android-sdk). Robolectric's Android -# framework jars have their own cache entry, keyed on their versions -# (app/build.gradle.kts), so the unit tests do not download them from -# Maven Central. +# the same way (.github/actions/android-sdk). Robolectric's jars have +# their own cache entry, keyed on their versions (app/build.gradle.kts). +# Gradle downloads from Google's mirror of Maven Central first +# (MAVEN_CENTRAL_MIRROR), because Maven Central's rate limit refuses +# downloads from the runners. # # D-Modem is a public submodule: the checkout needs no token. # @@ -48,6 +49,9 @@ concurrency: cancel-in-progress: ${{ github.event_name == 'pull_request' }} env: + # Google's mirror of Maven Central, which Gradle tries first (settings.gradle.kts): Maven Central's + # rate limit (HTTP 429) refuses downloads from the runners + MAVEN_CENTRAL_MIRROR: https://maven-central.storage-download.googleapis.com/maven2/ NDK_VERSION: "29.0.14206865" CMAKE_VERSION: "3.31.6" @@ -82,21 +86,22 @@ jobs: java-version: "21" - uses: gradle/actions/setup-gradle@v5 - with: - # (Robolectric's jars: their own cache, below) - gradle-home-cache-excludes: caches/modules-2/files-2.1/org.robolectric # Robolectric's Android framework jars (about 200 MB each, app/build.gradle.kts), in Gradle's # cache: their own cache entry, keyed on their versions, so a run does not download them # from Maven Central (its rate limit, HTTP 429) + # (the key: Robolectric's version and its jars' versions, then the files the entry holds; + # a run that downloads more files saves a new entry) - name: Robolectric's jars, key id: robolectric - run: echo "key=robolectric-$(grep -h 'android-all-instrumented:' app/build.gradle.kts | sort | sha256sum | cut -c1-16)" >> "$GITHUB_OUTPUT" + run: | + echo "prefix=robolectric-$({ grep -h '^robolectric' gradle/libs.versions.toml; grep -h 'android-all-instrumented:' app/build.gradle.kts; } | sort | sha256sum | cut -c1-16)-" >> "$GITHUB_OUTPUT" - id: robolectric-restore uses: actions/cache/restore@v5 with: path: ~/.gradle/caches/modules-2/files-2.1/org.robolectric - key: ${{ steps.robolectric.outputs.key }} + key: ${{ steps.robolectric.outputs.prefix }} + restore-keys: ${{ steps.robolectric.outputs.prefix }} - name: SDK packages uses: ./.github/actions/android-sdk @@ -131,16 +136,23 @@ jobs: # (saved also when a test fails: the jars that Gradle downloaded are good) - name: Robolectric's jars, downloaded id: robolectric-got - if: ${{ !cancelled() && steps.robolectric-restore.outputs.cache-hit != 'true' }} + if: ${{ !cancelled() }} + env: + PREFIX: ${{ steps.robolectric.outputs.prefix }} + RESTORED: ${{ steps.robolectric-restore.outputs.cache-matched-key }} run: | - d=~/.gradle/caches/modules-2/files-2.1/org.robolectric/android-all-instrumented - [ "$(find "$d" -name '*.jar' 2>/dev/null | wc -l)" -ge 2 ] && echo "save=true" >> "$GITHUB_OUTPUT" || true - - if: ${{ !cancelled() && steps.robolectric-got.outputs.save == 'true' }} + d=~/.gradle/caches/modules-2/files-2.1/org.robolectric + [ -d "$d" ] || exit 0 + key="$PREFIX$(cd "$d" && find . -type f | sort | sha256sum | cut -c1-16)" + if [ "$key" != "$RESTORED" ]; then + echo "key=$key" >> "$GITHUB_OUTPUT" + fi + - if: ${{ !cancelled() && steps.robolectric-got.outputs.key != '' }} uses: actions/cache/save@v5 continue-on-error: true with: path: ~/.gradle/caches/modules-2/files-2.1/org.robolectric - key: ${{ steps.robolectric.outputs.key }} + key: ${{ steps.robolectric-got.outputs.key }} - name: The APK's signer if: ${{ !cancelled() && hashFiles('app/build/outputs/apk/debug/app-debug.apk') != '' }} diff --git a/.github/workflows/apple.yml b/.github/workflows/apple.yml index faa8451..3f1f285 100644 --- a/.github/workflows/apple.yml +++ b/.github/workflows/apple.yml @@ -23,6 +23,11 @@ concurrency: group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} +env: + # Google's mirror of Maven Central, which Gradle tries first (settings.gradle.kts): Maven Central's + # rate limit (HTTP 429) refuses downloads from the runners + MAVEN_CENTRAL_MIRROR: https://maven-central.storage-download.googleapis.com/maven2/ + jobs: engine: runs-on: macos-latest diff --git a/settings.gradle.kts b/settings.gradle.kts index bbbb96b..bafa7c1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,14 +1,20 @@ +// MAVEN_CENTRAL_MIRROR (CI: Google's mirror of Maven Central): a mirror that Gradle tries before Maven +// Central itself, whose rate limit (HTTP 429) refuses downloads from CI's runners +// (pluginManagement comes first in a settings script: it reads the variable itself) pluginManagement { repositories { google() + System.getenv("MAVEN_CENTRAL_MIRROR")?.takeIf { it.isNotEmpty() }?.let { maven(it) } mavenCentral() gradlePluginPortal() } } +val mavenCentralMirror: String? = providers.environmentVariable("MAVEN_CENTRAL_MIRROR").orNull?.takeIf { it.isNotEmpty() } dependencyResolutionManagement { repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) repositories { google() + mavenCentralMirror?.let { maven(it) } mavenCentral() // usb-serial-for-android (USB serial adapters' drivers) is on JitPack only: JitPack for it alone exclusiveContent { From 60cd80c8f98d952af4234731707767fceb259029 Mon Sep 17 00:00:00 2001 From: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:50:00 +0000 Subject: [PATCH 4/4] Robolectric's jars: one configuration for each jar The SDK 28 tests failed: "Path is not a file: .../robolectric-jars/ android-all-instrumented-9-robolectric-4913185-2-i7.jar". In one configuration, Gradle keeps only the highest version of a module, so it resolved only the SDK 35 jar. Now each jar has its own configuration. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01B82eRSYSk1rgeTZ9ZWMcZL Signed-off-by: Neo-Desktop <321592+Neo-Desktop@users.noreply.github.com> --- app/build.gradle.kts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 60577c7..d23031c 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -209,14 +209,16 @@ val buildHostSsh = tasks.register("buildHostSsh") { // A new SDK in a test's @Config: add its jar here. Robolectric's DefaultSdkProvider gives the version // for its release (libs.versions.toml): "-robolectric--i". // -ProbolectricRepoUrl=: Robolectric downloads them itself from that mirror instead. -val robolectricJars = configurations.create("robolectricJars") { - isTransitive = false - isCanBeConsumed = false -} -dependencies { +// (one configuration for each jar: in one configuration, Gradle keeps only the highest version of a module) +val robolectricJars = mapOf( // SDK 28 (Android 9) and SDK 35 (Android 15), Robolectric 4.17's jars - robolectricJars("org.robolectric:android-all-instrumented:9-robolectric-4913185-2-i7") - robolectricJars("org.robolectric:android-all-instrumented:15-robolectric-13954326-i7") + 28 to "org.robolectric:android-all-instrumented:9-robolectric-4913185-2-i7", + 35 to "org.robolectric:android-all-instrumented:15-robolectric-13954326-i7", +).map { (sdk, jar) -> + configurations.create("robolectricJarsSdk$sdk") { + isTransitive = false + isCanBeConsumed = false + }.also { dependencies.add(it.name, jar) } } val robolectricJarsDir = layout.buildDirectory.dir("robolectric-jars") val syncRobolectricJars = tasks.register("syncRobolectricJars") {