Skip to content

[stable] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are packaged - #196721

Merged
auto-submit[bot] merged 3 commits into
flutter:flutter-3.50-candidate.0from
reidbaker-agent:cherry-pick-196465-to-stable
Nov 18, 2026
Merged

auto-submit[bot] merged 3 commits into
flutter:flutter-3.50-candidate.0from
reidbaker-agent:cherry-pick-196465-to-stable

Conversation

@reidbaker

@reidbaker reidbaker commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Issue Link:

#196444 original issue
and #196735 post submit failure that turned the tree red

Companion beta cherry-pick: #196747

Impact Description:

#192488, part of the migration to AGP's public Variant API, changed how the Flutter Gradle Plugin adds Flutter assets to an Android build. It shipped in 3.50.0 and in the current beta, 3.51.0-0.1.pre. Up to 3.47, a Gradle Copy task copied Flutter assets into the merged assets with Gradle's default excludes. Since #192488, they are registered as a generated assets source directory (variant.sources.assets.addGeneratedSourceDirectory).

AGP filters asset source directories with its ignoreAssetsPattern, which has a different default from Gradle's. That pattern drops files whose names start with . (such as .env) and folders whose names start with _ (such as _private/). On 3.50.0 and 3.51.0-0.1.pre, Android builds silently leave out assets declared in pubspec.yaml that load on iOS, on web, and in 3.47. At runtime, rootBundle.load fails with "Unable to load asset". This affects production apps that ship a .env file, for example with flutter_dotenv. The build gives no warning, so developers find out only when the app runs.

This cherry-pick, #196465, adds Flutter's assets as a transform of AGP's merged assets (SingleArtifact.ASSETS) after AGP's filtering, using a Gradle copy spec. That restores the set of files that 3.47 packaged while staying on the public Variant API.

Changelog Description:

[flutter/196444] When building for Android with Flutter 3.50.0, assets whose names start with a dot (such as .env) or an underscore folder were silently left out of the APK or AAB which caused a runtime failure.

Workaround:

Rename the affected assets and folders so they don't start with . or _, or stay on Flutter 3.47.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

  1. Run flutter create app, add assets/.env and assets/_private/file.txt to pubspec.yaml, and load them with rootBundle.
  2. Run flutter build apk, then unzip -l build/app/outputs/flutter-apk/app-release.apk | grep flutter_assets. Both files are listed.
  3. The integration test android_gradle_asset_merging_test.dart and the CopyFlutterAssetsTaskTest unit tests cover dotfiles, Gradle default excludes, stale-file removal, and collisions.

Cherry-pick conflict resolution:

FlutterPlugin.kt and FlutterPluginTest.kt conflicted. The 3.50 branch had a guard that threw a GradleException when AGP did not expose variant.sources.assets, plus a unit test for it. #196465 replaces that code path with a transform on SingleArtifact.ASSETS, so sources.assets is no longer used. The resolution takes #196465's version, which removes the guard and its test, matching master. The Flutter Gradle Plugin unit tests pass on this branch.

Bundled test fix:

This CP also includes the devicelab flavors_test fix from #196736 (2b91459d5fe), which fixes #196735. flavors_test read AssetManifest.bin from AGP's merge<Variant>Assets intermediate folder, which no longer contains Flutter's assets after #196465 moves them to a SingleArtifact.ASSETS transform. The app still builds and installs; the test now reads AssetManifest.bin from the built APK. Without this fix, Linux_pixel_7pro flavors_test and Windows_mokey flavors_test_win (presubmit: false in .ci.yaml) would fail in flutter-3.50-candidate.0 postsubmit.

flutter#196465)

Since flutter#192488, the Flutter Gradle plugin registered flutter_assets/ as a
generated assets source directory. AGP filters assets source directories
with androidResources.ignoreAssetsPattern, whose default drops files
whose name starts with "." (such as .env) and directories whose name
starts with "_". Those assets were missing from the APK and failed to
load at runtime.

CopyFlutterAssetsTask now transforms SingleArtifact.ASSETS instead: its
output is AGP's merged assets with flutter_assets/ copied over them, so
Flutter assets bypass the filter. This restores the pre-3.50 behavior,
and matches web and macOS, which ship these files without filtering. The
same wiring applies to library variants, so `flutter build aar` outputs
include these files again.

The task copies with a Gradle sync spec, so Gradle's default excludes
(.gitignore, .DS_Store, ._*, *~, ...) apply, as they did with the `Copy`
task before flutter#192488. AGP's compress step drops those files from the APK
either way. The default excludes don't cover `.env` or `_`-prefixed
directories.

Fixes flutter#196444

- A custom `ignoreAssetsPattern` no longer applies to Flutter assets. It
still applies to the app's own `src/main/assets`, and AGP's default
filtering of those is unchanged.
- When a file exists both in `flutter_assets/` and in the app's
`src/main/assets/flutter_assets/`, Flutter's copy wins again, as in
3.47.

- **Add-to-app, module included from source:** the host app's own asset
merge still drops `.env` and `_private/` with AGP's default pattern. The
Flutter Gradle plugin isn't applied to the host, so it can't change
this. This isn't a 3.50 regression: it happens on master, with this PR,
and at 557f863 (the parent of flutter#192488). Workaround: set a custom
`ignoreAssetsPattern` in the host. AARs from `flutter build aar` aren't
affected.
- **Deferred components:** feature modules register assets with `srcDirs
+=` (`templates/module/android/deferred_component/build.gradle.tmpl`),
so they drop these files on every version. I'll follow up on master
separately.

- [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 in-code documentation (doc comments with
`///`).
- [x] If this PR introduces a new feature or capability, I created and
linked a website documentation issue or PR in [flutter/website] (or
verified none is needed).
- [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: Reid-Agent <[email protected]>
(cherry picked from commit 6b90832)
@reidbaker
reidbaker requested a review from a team as a code owner November 16, 2026 22:13
@reidbaker reidbaker added the cp: review Cherry-picks in the review queue label Nov 16, 2026
@reidbaker
reidbaker requested review from jesswrd and removed request for a team November 16, 2026 22:13
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Nov 16, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies the Flutter Gradle Plugin to integrate Flutter assets into Android builds using a transform of the merged assets artifact (SingleArtifact.ASSETS) rather than adding them as a generated assets source directory. This prevents the Android Gradle Plugin's default ignoreAssetsPattern from filtering out valid Flutter assets like .env files or directories starting with an underscore. The CopyFlutterAssetsTask now merges the assets and ensures Flutter assets take precedence on path collisions. Relevant unit and integration tests have been updated to reflect and verify these changes. No review comments were provided, so there is no additional feedback.

@reidbaker reidbaker changed the title [stable] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… [stable] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are packaged Nov 16, 2026
flavors_test read AssetManifest.bin from AGP's merge<Variant>Assets
intermediate directory. Since flutter#196465, the Flutter Gradle Plugin adds
its assets with a transform of SingleArtifact.ASSETS, so that directory
no longer holds flutter_assets and the test failed with
PathNotFoundException. Read the manifest from the built APK instead,
which does not depend on AGP intermediates.

Fixes flutter#196735

(cherry picked from commit 9ea75ec)
package:archive 3.x types ArchiveFile.content as dynamic, and a
decompressed entry is only guaranteed to be a List<int>.

(cherry picked from commit 7220d98)

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 18, 2026
@auto-submit
auto-submit Bot merged commit 5ecbe85 into flutter:flutter-3.50-candidate.0 Nov 18, 2026
5 checks passed
auto-submit Bot pushed a commit that referenced this pull request Nov 18, 2026
…re packaged (#196747)

### Issue Link:
#196444

Bundled test fix for #196735 (postsubmit failure; see below).
Companion stable cherry-pick: #196721

### Impact Description:
[#192488](#192488), part of the migration to AGP's public Variant API, changed how the Flutter Gradle Plugin adds Flutter assets to an Android build. It shipped in 3.50.0 and in the current beta, 3.51.0-0.1.pre. Up to 3.47, a Gradle `Copy` task copied Flutter assets into the merged assets with Gradle's default excludes. Since #192488, they are registered as a generated assets source directory (`variant.sources.assets.addGeneratedSourceDirectory`).

AGP filters asset source directories with its `ignoreAssetsPattern`, which has a different default from Gradle's. That pattern drops files whose names start with `.` (such as `.env`) and folders whose names start with `_` (such as `_private/`). On 3.50.0 and 3.51.0-0.1.pre, Android builds silently leave out assets declared in `pubspec.yaml` that load on iOS, on web, and in 3.47. At runtime, `rootBundle.load` fails with "Unable to load asset". This affects production apps that ship a `.env` file, for example with `flutter_dotenv`. The build gives no warning, so developers find out only when the app runs.

This cherry-pick, [#196465](#196465), adds Flutter's assets as a transform of AGP's merged assets (`SingleArtifact.ASSETS`) after AGP's filtering, using a Gradle copy spec. That restores the set of files that 3.47 packaged while staying on the public Variant API.

### Changelog Description:
[flutter/196444] When building for Android, assets declared in `pubspec.yaml` whose names start with `.` (such as `.env`), or inside folders whose names start with `_`, are silently omitted from the APK and fail to load at runtime.

### Workaround:
Rename the affected assets and folders so they don't start with `.` or `_`, or stay on Flutter 3.47.

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
1. Run `flutter create app`, add `assets/.env` and `assets/_private/file.txt` to `pubspec.yaml`, and load them with `rootBundle`.
2. Run `flutter build apk`, then `unzip -l build/app/outputs/flutter-apk/app-release.apk | grep flutter_assets`. Both files are listed.
3. The integration test `android_gradle_asset_merging_test.dart` and the `CopyFlutterAssetsTaskTest` unit tests cover dotfiles, Gradle default excludes, stale-file removal, and collisions.

### Bundled test fix:
This CP also includes the devicelab `flavors_test` fix from [#196736](#196736) (`2b91459d5fe`), which fixes [#196735](#196735). `flavors_test` read `AssetManifest.bin` from AGP's `merge<Variant>Assets` intermediate folder, which no longer contains Flutter's assets after #196465 moves them to a `SingleArtifact.ASSETS` transform. The app still builds and installs; the test now reads `AssetManifest.bin` from the built APK. Without this fix, `Linux_pixel_7pro flavors_test` and `Windows_mokey flavors_test_win` (`presubmit: false` in `.ci.yaml`) would fail in `flutter-3.51-candidate.0` postsubmit.
@victorsanni victorsanni mentioned this pull request Nov 18, 2026
11 tasks done
auto-submit Bot pushed a commit that referenced this pull request Nov 19, 2026
Adds `CHANGELOG.md` entries for the 3.50.1 stable hotfix (#196756, #196721, #196127, #196035, #196418, #196800, #196796, #196895, #196383, #196923). Omits the infra-only #196760 and the `engine.version` sync #196932.

Tracker: #196743

### Edits to cherry-pick changelog descriptions
- All entries use the cherry-pick PR's "Changelog Description" verbatim, except for backticks around code terms (#196756, #196418, #196895, #196923) and a comma and trailing period in the #196418 entry.
- #196923 also cherry-picks #195006, so it has two entries, as listed in its "Changelog Description".

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants