Skip to content

Conversation

@bartekpacia
Copy link
Member

@bartekpacia bartekpacia commented Jan 25, 2025

drake

This PR attempts to fix #110559

This PR supersedes #147837

Original attempt at fixing this by @GaryQian: #112723

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group.

@github-actions github-actions bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. labels Jan 25, 2025
@bartekpacia bartekpacia force-pushed the bartekpacia/fix/gradle_always_generates_lockfiles_slow branch from 756b26d to 95b6fe2 Compare January 25, 2025 21:32
@bartekpacia bartekpacia changed the title Fix generateLockfiles executing its action at configuration time Fix FGP's generateLockfiles task always executing its action at configuration time Jan 25, 2025
@bartekpacia
Copy link
Member Author

bartekpacia commented Jan 25, 2025

Thought

The benefit of using Gradle lockfiles is not documented anywhere on Flutter's website. I think it should be – I can imagine large scale apps want to have as reproducible builds as possible, but without using Gradle lockfiles, there's no guarantee of this (for Android build of their Flutter app).

It wouldn't have to be a long doc, here's a draft.


Improve reproducibility of your Android builds by enabling Gradle dependency locking

Your pub dependencies (and all their transitive dependencies) are already pinned to specific versions in the pubspec.lock file. Unfortunately, because Flutter is multiplatform, it uses many build systems. This makes achieving reproducible builds more involved than simply relying on pubspec.lock.

To improve the reproducibility of Android builds of your Flutter app, we recommend using Gradle dependency locking (sometimes called "Gradle lockfiles").

If you're already using concrete versions for all your dependencies in build.gradle (e.g., specifying exact versions like 8.7.3), Gradle lockfiles might seem redundant at first glance, but they can still serve a purpose.

  • The Gradle buildscripts of Android implementation of Flutter plugins you depend on may specify exact versions of dependencies. But you don't know if the plugins' transitive dependencies also do this, or if they misbehave and use dynamic version ranges. In such case, having a lockfile is the best way to ensure you always resolve to exactly the same dependency tree (unless you explicitly update the lockfiles).

Enable Gradle dependency locking in your app

In android/settings.gradle[.kts], add the following code:

// ...

+buildscript {
+    dependencyLocking {
+        lockFile = file("${rootProject.projectDir}/buildscript-gradle.lockfile")
+        lockAllConfigurations()
+    }
+}

plugins {
    id("dev.flutter.flutter-plugin-loader")
    // ...

In android/build.gradle[.kts], add the following code:

subprojects {
    project.evaluationDependsOn(":app")
+    dependencyLocking {
+        ignoredDependencies.add("io.flutter:*")
+        lockFile = file("${rootProject.projectDir}/project-${project.name}.lockfile")
+        if (!project.hasProperty("local-engine-repo")) {
+            lockAllConfigurations()
+        }
+    }
}

Now run ./gradlew :generateLockfiles in the android directory. To update the lockfiles, run this task again.

@bartekpacia bartekpacia force-pushed the bartekpacia/fix/gradle_always_generates_lockfiles_slow branch from 95b6fe2 to ab277d5 Compare January 26, 2025 00:18
@bartekpacia bartekpacia requested review from gmackall, jesswrd and reidbaker and removed request for jesswrd January 26, 2025 22:26
@bartekpacia bartekpacia added this pull request to the merge queue Feb 4, 2025
Merged via the queue into master with commit 015cfa8 Feb 4, 2025
161 of 163 checks passed
@bartekpacia bartekpacia deleted the bartekpacia/fix/gradle_always_generates_lockfiles_slow branch February 4, 2025 03:10
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 4, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 5, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 7, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 8, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 9, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 10, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 11, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 20, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android Gradle Sync is time-consuming

3 participants