Skip to content

[FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… - #196465

Merged
reidbaker merged 6 commits into
flutter:masterfrom
joellemd:fix-android-dotfile-assets
Nov 16, 2026
Merged

reidbaker merged 6 commits into
flutter:masterfrom
joellemd:fix-android-dotfile-assets

Conversation

@joellemd

@joellemd joellemd commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Since #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 #192488. AGP's compress step drops those files from the APK either way. The default excludes don't cover .env or _-prefixed directories.

Fixes #196444

Behavior changes (for the release notes)

  • 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.

Not covered by this PR

  • 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 [AGP 9.1.0 Migration #6] Deliver Flutter assets as a generated assets source directory on the app path #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.

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [AI contribution guidelines] and understand my responsibilities, or I am not using AI tools.
  • 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 in-code documentation (doc comments with ///).
  • 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).
  • 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.

@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. team-android Owned by Android platform team d: docs/ flutter/flutter/docs, for contributors labels Nov 12, 2026
@joellemd

Copy link
Copy Markdown
Contributor Author

@mbcorona I am not able to open this for review, due to having other open PRs. Please check the solution and let me know!

@joellemd

Copy link
Copy Markdown
Contributor Author

@mbcorona, another data point that this is Android-specific and affects real projects: Datadog hit the same problem in dd-sdk-flutter and worked around it today. Their example and test apps load a generated .env with flutter_dotenv, exactly like the original report. On Flutter 3.50 that threw FileNotFoundError from dotenv.load() on Android, so they renamed the file to dd.env everywhere (pubspec asset entry and dotenv.load(fileName: 'dd.env')).

@mbcorona

Copy link
Copy Markdown
Member

Thanks for the fix @joellemd.
cc @flutter/android-reviewers about the open-PR limit keeping this in draft.

@joellemd
joellemd marked this pull request as ready for review November 12, 2026 21:41
@joellemd
joellemd requested a review from a team as a code owner November 12, 2026 21:41
@joellemd
joellemd requested review from reidbaker and removed request for a team November 12, 2026 21:42

@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 updates the Flutter Gradle integration to add Flutter assets as a transform of AGP's merged assets (SingleArtifact.ASSETS) rather than as a generated assets source directory, preventing valid assets like .env from being filtered out by AGP's ignoreAssetsPattern. The CopyFlutterAssetsTask is modified to copy the merged assets and overlay the flutter_assets directory. Feedback on these changes recommends using Gradle's FileSystemOperations to safely delete directories on Windows and setting read/write permissions on copied directories to avoid permission issues on Unix-like systems.

@reidbaker-agent

reidbaker-agent commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for picking this up quickly. We reproduced #196444 and built this PR locally (at 00ed805, before the rebase to b72c1e7). Summary of what we checked:

Verified working with this PR (unzip -l on the outputs; app assets .env, env, _private/file.txt, dir/.hidden):

We also looked at the alternatives (warning only, keeping AGP's defaults, a migrator, honoring the user's pattern). Web and macOS ship .env, _dir and similar files without filtering, and so did Android before 3.50. That makes this approach the one that restores consistent behavior across platforms.

Suggestions for the description:

  1. Narrow the add-to-app claim. When a host app includes the module from source, the host's own mergeDebugAssets still drops .env and _private/ with AGP's default pattern. That happens with this PR, on master, and at 557f863, so it isn't a 3.50 regression. The Flutter Gradle plugin isn't applied to the host, so this PR can't fix it. The workaround is a custom ignoreAssetsPattern in the host.
  2. Deferred components aren't covered. The feature modules register assets through srcDirs += (templates/module/android/deferred_component/build.gradle.tmpl:32), so they drop these files on every version. That's a reasonable master-only follow-up, not something for this PR.
  3. Release note: a user's ignoreAssetsPattern no longer applies to Flutter assets, and when a file exists in both places, Flutter's copy overwrites the app's src/main/assets copy again (as in 3.47). Both are worth a line in the description and the release notes.

Cherry-pick: git apply --check onto flutter-3.50-candidate.0 fails (conflicts in FlutterPlugin.kt and FlutterPluginTest.kt), so the 3.50 cherry-pick will need a manual PR. We'd suggest limiting it to the task, the wiring and the integration-test cases.

@joellemd

Copy link
Copy Markdown
Contributor Author

Suggestions for the description:

Thanks for checking all of these, and for the comparison with 557f863.

I've updated the description:

  1. Narrowed the add-to-app claim to flutter build aar outputs. The from-source host case now has its own note, saying it isn't a 3.50 regression and giving the host-side ignoreAssetsPattern workaround.
  2. Listed deferred components as not covered. I'll fix them in a separate PR against master.
  3. Added a "Behavior changes" section for the release notes: a user's ignoreAssetsPattern no longer applies to Flutter assets, and Flutter's copy wins on a path collision again, as in 3.47.

For 3.50, I'll open a manual cherry-pick PR against flutter-3.50-candidate.0 once this lands. It will include only CopyFlutterAssetsTask, the SingleArtifact.ASSETS wiring in FlutterPlugin.kt, and the integration-test cases.

@joellemd
joellemd force-pushed the fix-android-dotfile-assets branch from b72c1e7 to 004ea63 Compare November 13, 2026 19:39
@reidbaker reidbaker added the CICD Run CI/CD label Nov 13, 2026
@reidbaker

Copy link
Copy Markdown
Member

Did a quick review pass by hand, I dont like that this uses java.nio instead of the gradle copy spec. My agent will be adding a suggestion to this pr to make it easy to adopt.

Then will do another human review. goal is to land this monday then cherry pick to 3.50 so this can make the first patch release.

@reidbaker-agent

Copy link
Copy Markdown
Contributor

@reidbaker would like this to use a Gradle copy spec instead of the hand-written java.nio copy in CopyFlutterAssetsTask.

Why: the transform onto SingleArtifact.ASSETS is what fixes #196444. .env and _-prefixed directories are only dropped by AGP's ignoreAssetsPattern, not by Gradle's default excludes, so a copy spec in the same place fixes the bug too.

java.nio is broader than the copy spec Flutter used in 3.47. The 3.47 copy spec applied Gradle's default excludes, so .git/, .gitignore, .gitattributes, .svn/, CVS/, *~, #*#, .#*, .DS_Store and ._* were never copied. The java.nio copy in this PR stages all of them, and CopyFlutterAssetsTaskTest ("stages flutter assets whose names AGP or Gradle would filter by default") asserts that it does.

That expansion turns out not to change what users get. We built the PR head (004ea63) locally. The transform output contains .DS_Store, .gitignore and a~, but AGP's later compress<Variant>Assets step drops them, so they're absent from the release APK. That matches 3.47 (557f863). So the KDoc's reason for java.nio ("copy specs ... would drop those assets too") doesn't hold: those assets are dropped downstream either way. The broader copy adds custom code and a test that asserts behavior users never see.

Results with a copy spec (local builds, same app):

  • .env, _private/file.txt and dir/.hidden ship in the debug and release APKs and in the debug and release AARs.
  • .DS_Store, .gitignore and a~ are absent, the same as with the PR as-is and with 3.47.
  • On a path collision with src/main/assets/flutter_assets/, Flutter's asset wins, as before.
  • android_gradle_asset_merging_test.dart passes. The only Gradle unit test that changes is the CopyFlutterAssetsTaskTest case above, which would assert that those files are excluded instead.
  • filePermissions needs Gradle 8.3 or newer. Flutter's minimum is 9.3.1 (DependencyVersionChecker), so this also works for the 3.50 cherry-pick.

What the copy spec removes:

  • the manual delete, because sync prunes stale outputs
  • the symlink gap, because Files.walk without FOLLOW_LINKS skips symlinked directories
  • the per-file setReadable / setWritable calls

That's about 20 fewer lines in the task.

Suggested copy():

@TaskAction
fun copy() {
    // sync() prunes files that are no longer produced, so no separate delete is needed.
    fileSystemOperations.sync {
        into(destinationDir)
        from(mergedAssetsDir)
        // The engine loads assets from `flutter_assets/` by default, so keep the prefix.
        from(intermediateDir.dir(FLUTTER_ASSETS_DIRECTORY_NAME)) {
            into(FLUTTER_ASSETS_DIRECTORY_NAME)
        }
        // Flutter's assets are copied last, so on a path collision they replace the merged
        // native asset, as they did before 3.50.
        duplicatesStrategy = DuplicatesStrategy.INCLUDE
        // Assets from the pub cache can be read-only, and a packaging step downstream has to be
        // able to replace the copy.
        filePermissions {
            user {
                read = true
                write = true
            }
        }
    }
}

The KDoc paragraph about java.nio would then say that copy specs apply Gradle's default excludes, the same as releases before 3.50.

Separately, and not caused by this PR: AssetManifest.bin still lists .DS_Store, .gitignore and a~ when they sit in a directory listed in the pubspec, even though the APK doesn't contain them. The same happens on 3.47. It might be worth an issue so the tool stops listing files that never ship.

@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 13, 2026
@joellemd

Copy link
Copy Markdown
Contributor Author

Did a quick review pass by hand, I dont like that this uses java.nio instead of the gradle copy spec. My agent will be adding a suggestion to this pr to make it easy to adopt.

Then will do another human review. goal is to land this monday then cherry pick to 3.50 so this can make the first patch release.

Adopted the suggested copy(), thanks.

@auto-submit

auto-submit Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/196465, Failed to enqueue flutter/flutter/196465 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@reidbaker reidbaker added the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Nov 16, 2026
@auto-submit

auto-submit Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

auto label is removed for flutter/flutter/196465, Failed to enqueue flutter/flutter/196465 with HTTP 400: Pull request Required status check "Check Code Freeze" is expected..

@joellemd

Copy link
Copy Markdown
Contributor Author

@reidbaker anything needed from my side?

@reidbaker

Copy link
Copy Markdown
Member

@reidbaker anything needed from my side?

No dealing with some presubmit infra that is malformed. I just need to flip the right levers in the background to get this into a good state while the infra team works on making it automatic.

@reidbaker
reidbaker added this pull request to the merge queue Nov 16, 2026
@reidbaker

Copy link
Copy Markdown
Member

OK it was added to the merge queue, Once it is on master I will get this cherry picked to 3.50.1 thank you again for both your bug and contribution. And personally I am sorry I cause this regression for you.

@joellemd

Copy link
Copy Markdown
Contributor Author

Thanks @reidbaker for the quick review and for backporting it to 3.50.1, much appreciated! And no worries at all about the regression. Glad I could help get it fixed.

Merged via the queue into flutter:master with commit 6b90832 Nov 16, 2026
35 checks passed
@reidbaker reidbaker added the cp: stable cherry pick this pull request to stable release candidate branch label Nov 16, 2026
reidbaker pushed a commit to reidbaker-agent/flutter that referenced this pull request 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)
@reidbaker reidbaker added the cp: beta cherry pick this pull request to beta release candidate branch label Nov 17, 2026
reidbaker pushed a commit to reidbaker-agent/flutter that referenced this pull request Nov 17, 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)
opensource-fork-sync Bot pushed a commit to cla7aye15I4nd/opensource-flutter__flutter that referenced this pull request Nov 17, 2026
…ter#196736)

`flavors_test` read `AssetManifest.bin` from AGP's intermediate
directory,

`build/app/intermediates/assets/paidDebug/mergePaidDebugAssets/flutter_assets/`.

Since flutter#196465, the Flutter Gradle Plugin adds its assets with a
transform of
`SingleArtifact.ASSETS`, so AGP's `merge<Variant>Assets` output no
longer holds
`flutter_assets`. The test then failed with `PathNotFoundException`,
even though
the install succeeded and the APK has the assets. The failure was
consistent, so
it was not flaky.

This change reads `assets/flutter_assets/AssetManifest.bin` from the
built APK,
`build/app/outputs/flutter-apk/app-paid-debug.apk`, with
`package:archive`
(devicelab already depends on it). The test no longer depends on AGP
intermediate paths, which are not a stable API.

Affected postsubmit targets (both run `flavors_test`):
- `Linux_pixel_7pro flavors_test`
- `Windows_mokey flavors_test_win`

Fixes flutter#196735

## 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 `///`).
- [ ] 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.

This PR changes a test only.

[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[AI contribution guidelines]:
https://github.com/flutter/flutter/blob/main/docs/contributing/AI-contribution-guidelines.md
[Tree Hygiene]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md
[test-exempt]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests
[Flutter Style Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md
[Features we expect every widget to implement]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement
[CLA]: https://cla.developers.google.com/
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
reidbaker pushed a commit to reidbaker-agent/flutter that referenced this pull request Nov 17, 2026
…ache the task

AGP 9.3.1 reads a variant's DSL-less versionCode only from the main source set's
manifest, and injects it into the merged manifest only when it is positive.
Match that instead of simulating overlay merging, which removes the tools:remove,
tools:node, and namespace-prefix handling. A versionCode of 0 or less now fails
the build with the same actionable message.

- Move ManifestVersionCode into tasks/ManifestVersionCodeTaskHelper, which also
  registers the task, following the EnableHcppManifestTaskHelper pattern.
- Make ManifestVersionCodeTask @CacheableTask with one RELATIVE @InputFile.
- Catch IOException next to SAXException.
- Restore the GradleException and assertTrue imports in FlutterPluginTest that
  the rebase onto flutter#196465 dropped.
- Restructure the new split-per-abi integration tests into a group of linear
  tests with small named helpers.
- Add gradle/AGENTS.md rules for task-produced variant sources.
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Nov 17, 2026
flutter/flutter@d8bd864...2f09f96

2026-11-17 [email protected] Analyze every flutter create template, and fix the package_ffi lint (flutter/flutter#196165)
2026-11-17 [email protected] Roll Dart SDK from 50debf3c9757 to 26e38955d9d4 (3 revisions) (flutter/flutter#196772)
2026-11-17 [email protected] Manual roll ICU from b09986242cfb to d3c612f44146 (1 revision) (flutter/flutter#196713)
2026-11-17 [email protected] Roll Skia from 4f6b3a8d8565 to 503a380ebecc (19 revisions) (flutter/flutter#196768)
2026-11-17 [email protected] iOS: Don't mock UIView animations in keyboard spring animation test (flutter/flutter#196755)
2026-11-17 [email protected] [flutter_tools] Preserve index.html across --web-content-hash transitions (flutter/flutter#196491)
2026-11-17 [email protected] Fix TextStyle background color fade-out when lerping to null (flutter/flutter#196153)
2026-11-17 [email protected] Update desktop engine TESTOWNERS (flutter/flutter#196732)
2026-11-17 [email protected] [flutter_tools] Do not copy app-only build type properties onto library plugins (flutter/flutter#196692)
2026-11-17 [email protected] [flutter_tools] Remove service and runner ambient context getters (flutter/flutter#196571)
2026-11-17 [email protected] Bump customer tests (flutter/flutter#196740)
2026-11-17 [email protected] Take customer_testing_flame out of bringup (flutter/flutter#196570)
2026-11-17 [email protected] [devicelab] Read AssetManifest.bin from the APK in flavors_test (flutter/flutter#196736)
2026-11-17 [email protected] [flutter_tools] Fix flaky tool_tests_general by moving spawnUri tests to integration shard (flutter/flutter#195999)
2026-11-17 [email protected] Roll Dart SDK from 3e069c6fdbde to 50debf3c9757 (2 revisions) (flutter/flutter#196706)
2026-11-16 [email protected] [web] Record build finish synchronously in renderScene and fix dropped frame timings (flutter/flutter#195947)
2026-11-16 [email protected] Do not reveal obscured character when input is rejected by inputFormatters (flutter/flutter#195022)
2026-11-16 [email protected] Cla draft follow up: add waiting for response (flutter/flutter#196686)
2026-11-16 [email protected] Roll pub packages (flutter/flutter#196684)
2026-11-16 [email protected] Roll Packages from 015df97 to 4c6a7d3 (8 revisions) (flutter/flutter#196681)
2026-11-16 [email protected] Skip Vulkan impeller_unittests on macOS (flutter/flutter#196282)
2026-11-16 [email protected] Move the task runners out of Flutter Engine (flutter/flutter#196267)
2026-11-16 [email protected] [FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… (flutter/flutter#196465)
2026-11-16 [email protected] iOS: Add Obj-C model for platform view composition params (flutter/flutter#196498)
2026-11-16 [email protected] [Windows] Normalize Shift key messages with a non-standard scan code (flutter/flutter#193675)
2026-11-16 [email protected] Roll Skia from 118eaff3deb4 to 4f6b3a8d8565 (3 revisions) (flutter/flutter#196672)
2026-11-16 [email protected] Roll Dart SDK from c91e8b6674e2 to 3e069c6fdbde (4 revisions) (flutter/flutter#196669)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
auto-submit Bot pushed a commit that referenced this pull request Nov 18, 2026
… are packaged (#196721)

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

Companion beta cherry-pick: #196747

### 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 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?

### 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.

### 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](#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.50-candidate.0` postsubmit.
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.
jose-pr pushed a commit to Boriken-Dev/flutter that referenced this pull request Nov 23, 2026
… are packaged (#196721)

### Issue Link:
flutter/flutter#196444 original issue
and flutter/flutter#196735 post submit failure that turned the tree red

Companion beta cherry-pick: flutter/flutter#196747

### Impact Description:
[#192488](flutter/flutter#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](flutter/flutter#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?

### 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.

### 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](flutter/flutter#196736) (`2b91459d5fe`), which fixes [#196735](flutter/flutter#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD cp: beta cherry pick this pull request to beta release candidate branch cp: stable cherry pick this pull request to stable release candidate branch d: docs/ flutter/flutter/docs, for contributors platform-android Android applications specifically team-android Owned by Android platform team tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flutter 3.50.0 cannot load assets with filenames starting with a dot

5 participants