Skip to content

Register the Flutter compile task lazily from the variant API for app projects - #6

Open
reidbaker-agent wants to merge 2 commits into
agp-ndk-fallbackfrom
agp-assets-onvariants
Open

Register the Flutter compile task lazily from the variant API for app projects#6
reidbaker-agent wants to merge 2 commits into
agp-ndk-fallbackfrom
agp-assets-onvariants

Conversation

@reidbaker-agent

@reidbaker-agent reidbaker-agent commented Jul 22, 2026

Copy link
Copy Markdown
Owner

Phase 6 of 11 of the AGP public-API migration; stacked on #5.

Phase P5, commit 1 of 2 (P5a), of the AGP public-API migration
(flutter#180137, flutter#166550):

  • For application projects, compileFlutterBuild<Variant> (FlutterTask)
    is now registered inside the consolidated androidComponents.onVariants
    block as a lazy TaskProvider, configured entirely from the public
    variant API: minSdk from Variant.minSdk.apiLevel, flavor from
    Variant.flavorName, and the Flutter build mode from
    buildModeFor(variant.buildType, variant.debuggable) so custom
    debuggable build types keep mapping to debug engine artifacts.
    Registration is gated by shouldConfigureFlutterTask on the computed
    assemble task name (new name-based overload), mirroring the legacy
    callback's gating.
  • addFlutterDeps is split: addFlutterDepsForApp (per-ABI versionCode,
    legacy assets copy into the merged-assets dir, processResources hook)
    looks the compile task up by name instead of registering it;
    addFlutterDepsForModule keeps the full legacy path for add-to-app
    module projects until that path migrates. The always-null
    packageAssets/isUsedAsSubproject dead code and the duplicated
    processResources hook in the application variant callback are
    removed.

No behavior change intended for what gets built; the assets delivery
mechanism changes in the next commit (P5b).

Verification note: FGP unit tests could not run in this sandbox (network
policy blocks dl.google.com); run 'gradle test' (both AGP axes) in CI.

Revert-safe (with P5b) until P6 lands.

CI must run the FGP unit tests (the Kotlin suite in packages/flutter_tools/gradle could not run in the delivery sandbox: dl.google.com returns 403, so AGP artifacts do not resolve).

… projects

Phase P5, commit 1 of 2 (P5a), of the AGP public-API migration
(flutter#180137, flutter#166550):

- For application projects, compileFlutterBuild<Variant> (FlutterTask)
  is now registered inside the consolidated androidComponents.onVariants
  block as a lazy TaskProvider, configured entirely from the public
  variant API: minSdk from Variant.minSdk.apiLevel, flavor from
  Variant.flavorName, and the Flutter build mode from
  buildModeFor(variant.buildType, variant.debuggable) so custom
  debuggable build types keep mapping to debug engine artifacts.
  Registration is gated by shouldConfigureFlutterTask on the computed
  assemble task name (new name-based overload), mirroring the legacy
  callback's gating.
- addFlutterDeps is split: addFlutterDepsForApp (per-ABI versionCode,
  legacy assets copy into the merged-assets dir, processResources hook)
  looks the compile task up by name instead of registering it;
  addFlutterDepsForModule keeps the full legacy path for add-to-app
  module projects until that path migrates. The always-null
  packageAssets/isUsedAsSubproject dead code and the duplicated
  processResources hook in the application variant callback are
  removed.

No behavior change intended for what gets built; the assets delivery
mechanism changes in the next commit (P5b).

Verification note: FGP unit tests could not run in this sandbox (network
policy blocks dl.google.com); run 'gradle test' (both AGP axes) in CI.

Revert-safe (with P5b) until P6 lands.
…app path

Phase P5, commit 2 of 2 (P5b), of the AGP public-API migration
(flutter#180137, flutter#166550):

- New CopyFlutterAssetsTask stages flutter_assets/** from the Flutter
  build output into its own output directory (modeled on
  CopyFlutterJniLibsTask, including the overlapping-outputs rationale),
  applying the user read+write file permissions the old Copy task set.
- For application projects, copyFlutterAssets<Variant> is registered in
  the consolidated onVariants block as a lazy TaskProvider and wired via
  variant.sources.assets.addGeneratedSourceDirectory. AGP now merges
  Flutter's assets like any other assets source; collisions with user
  assets resolve by source-set priority instead of the old post-merge
  overwrite (documented behavior change). A missing assets source set
  fails loudly instead of silently building an APK without Flutter
  assets.
- The legacy app-path assets copy (into mergeAssets.outputDir), its
  processResources/cleanMergeAssets task-graph surgery, and the manual
  compress<V>Assets dependsOn wiring are deleted for app projects; AGP
  owns those edges now. The application variant callback is reduced to
  the per-ABI versionCode override and the flutter-apk copy, both of
  which migrate in the next phase. The add-to-app module path is
  unchanged (still the full legacy copy) until it migrates.
- copyFlutterAssets<Variant> changes type from org.gradle.api.tasks.Copy
  to CopyFlutterAssetsTask and is now registered lazily (documented
  breaking change for build scripts that referenced it by type).
- Tests: new CopyFlutterAssetsTaskTest executes the task against real
  files (staging layout, permission bits, non-asset exclusion, stale
  output cleanup). The FlutterPluginTest filePermissions test built on
  capturing the legacy Copy registration is superseded by it.

Verification (CI): gradle unit tests both AGP axes; integration
builddir/obfuscate/jni/print_build_variants/deferred_components_assets;
add-to-app source smoke + flutter build aar; asset-staleness rebuild
check; config-cache per baseline.

Revert-safe until P6 lands.
@reidbaker
reidbaker force-pushed the agp-assets-onvariants branch from 2654136 to bd2c850 Compare August 6, 2026 14:37
pull Bot pushed a commit to Little-Star888/flutter that referenced this pull request Aug 12, 2026
…on documentation (flutter#190842)

There are 2 files in this pr. One is a document the ai used to keep
track of work. More importantly it acts kind of like issues so it
references the items in future prs. The second is user facing website
documentation. I do not know if we will use it verbatim but for the set
of prs lets treat that md doc as human understandable documentation that
we must understand before landing the next pr.

Reviewers: When the pr is out of draft and your comments are fully
addressed please prioritize this pr over other work. The review bar is
higher, the number of reviews has more people and the work for the next
pr is already done.
 - @reidbaker 
---
Standard review context for this pr stack

This is PR is part of an 11 pr stack to migrate the "newdsl"
`gradle-api` specifically in agp 9.1.0.
The complete stack has pass pre submits, post submits and customer
tests.
https://flutter-dashboard.appspot.com/#/build?repo=flutter&branch=experimental/agp-gradle-api

All of the code was LLM authored. A mix of manual prompting, automatic
prompting, several models and adversarial review. The combined sessions
are enough that I cannot include relevant prompts like I have been doing
on other prs.

If you want to review the pr stack you can find it here. These prs will
be abandoned/closed as prs land into flutter/flutter.
1. reidbaker-agent#1 (branch:
agp-api-doc)
2. reidbaker-agent#2 (branch:
agp-internal-utils)
3. reidbaker-agent#3 (branch:
agp-buildmode-deps)
4. reidbaker-agent#4 (branch:
agp-plugin-buildtypes)
5. reidbaker-agent#5 (branch:
agp-ndk-fallback)
6. reidbaker-agent#6 (branch:
agp-assets-onvariants)
7. reidbaker-agent#7 (branch:
agp-apk-copy-versioncode)
8. reidbaker-agent#8 (branch:
agp-add-to-app)
9. reidbaker-agent#9 (branch:
agp-aar-script)
10. reidbaker-agent#10 (branch:
agp-newdsl-flip)
11. reidbaker-agent#11 (branch:
agp-gradle-api)

Follow up work is tracked in
flutter#190964

This work is urgent in the sense that we are worried that android will
publish agp 10 with no opt out but not so urgent that we are willing to
break flutter users because we didn't review or understand the code
because we were in a rush.

Breaking changes are expected as part of this work. There are patterns
the android team explicitly does not want apps to use and apis that have
no equivalent.

As part of the effort to ensure this work does not slip into ai slop,
prs from this stack will be reviewed by me (@reidbaker) before asking
for review. Then we will have 2 android expert reviewers also review the
every pr.

---
Agent authored pr description
This is PR 1 of 11 in the AGP 9.1.0 / public `gradle-api` migration
stack.

It adds the contributor-facing and website draft documentation for the
Flutter Gradle Plugin's migration to the Android Gradle Plugin public
Variant API, which unblocks building Flutter Android apps with AGP's
`newDsl=true` enabled.

Part of flutter#180137 and flutter#166550.

## Pre-launch Checklist

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

---------

Co-authored-by: reidbaker-agent <reidbaker@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants