Repository navigation
[FGP] Add Flutter assets after AGP's asset merge so dotfiles are pack… - #196465
Conversation
|
@mbcorona I am not able to open this for review, due to having other open PRs. Please check the solution and let me know! |
|
@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')). |
|
Thanks for the fix @joellemd. |
There was a problem hiding this comment.
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.
00ed805 to
b72c1e7
Compare
|
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 (
We also looked at the alternatives (warning only, keeping AGP's defaults, a migrator, honoring the user's pattern). Web and macOS ship Suggestions for the description:
Cherry-pick: |
Thanks for checking all of these, and for the comparison with 557f863. I've updated the description:
For 3.50, I'll open a manual cherry-pick PR against |
b72c1e7 to
004ea63
Compare
|
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 would like this to use a Gradle copy spec instead of the hand-written Why: the transform onto
That expansion turns out not to change what users get. We built the PR head (004ea63) locally. The transform output contains Results with a copy spec (local builds, same app):
What the copy spec removes:
That's about 20 fewer lines in the task. Suggested @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 Separately, and not caused by this PR: |
Adopted the suggested copy(), thanks. |
|
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.. |
|
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 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. |
|
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. |
|
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. |
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)
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)
…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
…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.
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
… 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.
…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.
… 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.
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 aaroutputs 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
Copytask before #192488. AGP's compress step drops those files from the APK either way. The default excludes don't cover.envor_-prefixed directories.Fixes #196444
Behavior changes (for the release notes)
ignoreAssetsPatternno longer applies to Flutter assets. It still applies to the app's ownsrc/main/assets, and AGP's default filtering of those is unchanged.flutter_assets/and in the app'ssrc/main/assets/flutter_assets/, Flutter's copy wins again, as in 3.47.Not covered by this PR
.envand_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 customignoreAssetsPatternin the host. AARs fromflutter build aararen't affected.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
///).