Repository navigation
Cache Gradle downloads in the Android build - #7
Merged
Merged
Conversation
build-android had no Gradle cache (the Flutter action caches the Flutter SDK, not ~/.gradle), so every run downloaded all of Gradle's dependencies, including the plugins for Flutter's own Gradle plugin loader. That is slow, and makes the job fail whenever those repositories hiccup: a fork run failed with the Gradle Plugin Portal answering "Could not find org.jetbrains.kotlin:kotlin-stdlib:2.2.21" for an artifact that exists, and passed on re-run. Gradle's own download retries don't help there, as a not-found response is treated as definite. Add gradle/actions/setup-gradle@v6 to build-android, before the first Gradle build. Its init scripts apply to every Gradle run in the job, including those started by `flutter build apk`, and it caches the Gradle User Home (dependencies, wrapper distributions, generated jars) between runs. Only default-branch runs write the cache; branch and pull-request runs restore it. build-android is the only job that runs Gradle; maestro-e2e uses the APK it uploads. It uses the default (enhanced) cache provider: proprietary, under the Gradle Technologies Terms of Use, free for public repositories, with restore-key matching and cleanup. `cache-provider: basic` is the MIT-licensed alternative. No retry around the build step: with a warm cache the repositories are rarely contacted, and a retry would mostly delay genuine failures. Testing: - Workflow YAML parses; the step is in build-android immediately before "Build Android (release)". - Merges cleanly with the version-fixes and prerelease ordering branches (dwd#5, dwd#6). - flutter analyze: no issues. flutter test: all 1044 passed. vendor/xmpp_stone dart test: all 190 passed. - Maestro flows not run locally: CI-only change; the CI maestro-e2e job covers them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The
build-androidjob has no Gradle cache. The Flutter action caches the Flutter SDK, not~/.gradle. So every run downloads all of Gradle's dependencies again, including the plugins for Flutter's own Gradle plugin loader.That makes the job slower, and it makes it fail whenever those servers have a hiccup. On my fork, one run failed while resolving Flutter's plugin loader because the Gradle Plugin Portal answered "not found" for an artifact that exists:
A re-run of the same commit passed. Gradle's own download retries don't cover this kind of failure, because a "not found" response counts as a definite answer and isn't retried.
Change
Add
gradle/actions/setup-gradle@v6tobuild-android, just before the first Gradle build. It installs init scripts that apply to every Gradle run in the job, including the onesflutter build apkstarts. It caches Gradle's home directory between runs: dependencies, wrapper distributions and generated jars.This is the only job that runs Gradle.
maestro-e2euses the APK thatbuild-androidproduced.Behaviour worth knowing:
main's cache but don't save their own. So the benefit starts after the firstmainrun with this change.~/.m2/toolchains.xml, which the Flutter build doesn't use.Licensing: the default enhanced cache provider uses Gradle's proprietary
gradle-actions-cachinglibrary under the Gradle Technologies Terms of Use. It is free for public repositories (DISTRIBUTION.md). If you'd rather keep CI fully open source,cache-provider: basicis an MIT-licensed alternative built onactions/cache. The trade-off: it only matches the cache exactly on a hash of the repo's Gradle files, with no partial matching or cleanup, so the first run after any Gradle file change starts from an empty cache. It's a one-line change either way.I considered
actions/setup-javawithcache: gradleand decided against it. It would also pin the JDK version, and its cache only matches exactly on the repo's Gradle files.Testing
build-androidimmediately beforeBuild Android (release).flutter analyze,flutter testandvendor/xmpp_stonedart testpass. The app code is unchanged.build-androidpassed, with the release and debug builds both green under the action. The action behaved as documented for a branch run. It used theenhancedprovider withcache-read-only: true. It logged "Gradle User Home cache not found. Will initialize empty." on restore, and "Cache is read-only: will not save state" in the post step. It also produced the job summary (Gradle 9.3.1,assembleReleaseandassembleDebugsuccessful).maestro-e2epassed against the APK built this way. Every other job passed, apart frombuild-macosandbuild-ios, which GitHub never started because of macOS runner capacity; this change doesn't touch them. Cache hits can only show up onmain, after the first run there has saved the cache.🤖 Generated with Claude Code