Skip to content

Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)"#182522

Merged
auto-submit[bot] merged 37 commits into
flutter:masterfrom
camsim99:reland_flags
Mar 18, 2026
Merged

Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)"#182522
auto-submit[bot] merged 37 commits into
flutter:masterfrom
camsim99:reland_flags

Conversation

@camsim99
Copy link
Copy Markdown
Contributor

@camsim99 camsim99 commented Feb 18, 2026

Overview

Re-lands #181632 which TLDR does the following:

Same old same old changes from original PR

New changes/fixes

Note

This re-land was required because when previously submitted, it caused b/483299339. I have confirmed that this bug has been fixed in this PR; see go/flutter-android-setting-flags-in-manifest-perf-comparison for A/B test results with the previous version of this PR (#181632) and commit d6d4a07 of this PR.

  • [Critical change] To fix the bug caught by b/483299339, --merged-platform-ui-thread flag is added to FlutterEngineFlags
  • [Behavior change, not critical] To avoid more bugs like b/483299339, FlutterLoader allows unrecognized flags specified by the command line or Intent extras to be used to initialize the engine for now (same behavior as before my original change but I plan to secure this in the future; see [Android] Only allow known engine flags specified on the command line #182557)
  • [Small refactor] To speed up manifest argument processing time, FlutterLoader loops through all recognized FlutterEngineFlags to check if they are present in an application's manifest versus looping through all metadata in an application's manifest and looking for recognized FlutterEngineFlags (small improvement for apps with large manifests)
  • [Small refactor] To speed up command line argument processing time, FlutterLoader processes the --aot-shared-library-name flag in the same loop as the other flags, reducing the number of loops ensureInitializationComplete has to do (minimal improvement perf-wise but kept it in because it's more readable to me)

Full description

(Mostly copied from #181632)

Note

This PR is based on conversation & feedback on go/flutter-android-harden-engine-shell-arguments.

Adds a mechanism for setting Android engine flags via the manifest. If a flag is specified on the command line and in manifest metadata, the value specified on the command line will take precedence. Documentation is added on this mechanism

Additionally, this PR removes the exposure of--cache-sksl command line flag as per https://github.com/flutter/flutter/issues/140310#issuecomment-2708459007.

Additionally, this PR adds documentation for the only two supported ways of setting engine flags moving forward -- via the command line or manifest. The Intent mechanism will be removed when #180686 is completed (intended to be a follow up to this PR).

As the unit tests in this PR only cover setting flags via manifest in debug mode, I will follow up this PR with an integration test to test that flags are appropriately respected/ignored in release mode. See #178383 for my currently working but WIP draft.

Part of #172553.

Follow up work:

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. 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.

camsim99 and others added 16 commits February 10, 2026 11:06
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…manifest (take 2) (flutter#181632)

A continuation of flutter#177127.
Copying from there:

# Overview

> [!NOTE]  
> This PR is based on conversation & feedback on
go/flutter-android-harden-engine-shell-arguments.

Adds a mechanism for setting Android engine flags via the manifest. If a
flag is specified on the command line and in manifest metadata, the
value specified on the command line will take precedence. Documentation
is added on this mechanism

Additionally, this PR removes the exposure of`--cache-sksl` command line
flag as per
[https://github.com/flutter/flutter/issues/140310#issuecomment-2708459007](https://www.google.com/url?q=https://github.com/flutter/flutter/issues/140310%23issuecomment-2708459007&sa=D&source=docs&ust=1761156167162464&usg=AOvVaw3a8ubXTtv3apknY2-P9dKe).

Additionally, this PR adds documentation for the only two supported ways
of setting engine flags moving forward -- via the command line or
manifest. The `Intent` mechanism will be removed when
flutter#180686 is completed (intended
to be a follow up to this PR).

As the unit tests in this PR only cover setting flags via manifest in
debug mode, I will follow up this PR with an integration test to test
that flags are appropriately respected/ignored in release mode. See
flutter#178383 for my currently working
but WIP draft.

Part of flutter#172553.

# Follow up work:

## Add integration test for this new added mechanism
This will land as an immediate follow-up to this PR. WIP in
flutter#178383.

## Remove support for setting shell arguments via `Intent`
This task will be a follow up to this work + the integration test
landing, and will complete work for
flutter#172553. See
flutter#180686 for details.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
@github-actions github-actions Bot added platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels. engine flutter/engine related. See also e: labels. d: examples Sample code and demos team-android Owned by Android platform team team-engine Owned by Engine team d: docs/ flutter/flutter/docs, for contributors labels Feb 18, 2026
@github-actions github-actions Bot removed the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 19, 2026
@camsim99 camsim99 marked this pull request as ready for review February 19, 2026 21:34
@camsim99 camsim99 requested a review from a team as a code owner February 19, 2026 21:34
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 17, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Mar 17, 2026
Merged via the queue into flutter:master with commit 994b73f Mar 18, 2026
188 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 18, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Mar 19, 2026
flutter/flutter@d117642...dd64978

2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from 2fb5fa71eb12 to f0a13e5efbad (2 revisions) (flutter/flutter#183830)
2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from ae3d36cb9e29 to 2fb5fa71eb12 (3 revisions) (flutter/flutter#183823)
2026-03-18 94012149+richardexfo@users.noreply.github.com Linux reuse sibling (flutter/flutter#183653)
2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from 84a180a1fa80 to ae3d36cb9e29 (4 revisions) (flutter/flutter#183812)
2026-03-18 1961493+harryterkelsen@users.noreply.github.com fix(web): handle asynchronously disposed platform views (flutter/flutter#183666)
2026-03-17 87018443+mayanksharma9@users.noreply.github.com (Test cross-imports) Remove legacy Material import from sliver_constraints_test (flutter/flutter#183351)
2026-03-17 74057391+jhonathanqz@users.noreply.github.com Fix Android Studio pluginsPath when version is unknown (do not use 0.0) (flutter/flutter#182681)
2026-03-17 50643541+Mairramer@users.noreply.github.com Fixes animation glitch into bottom sheet (flutter/flutter#183303)
2026-03-17 ahmedsameha1@gmail.com Handle#6537 second grouped test (flutter/flutter#182529)
2026-03-17 ahmedsameha1@gmail.com Add a Clarification for the docs of suggestionsBuilder of SearchAnchor (flutter/flutter#183106)
2026-03-17 nate.w5687@gmail.com Remove obsolete null checks from style guide (flutter/flutter#181703)
2026-03-17 jason-simmons@users.noreply.github.com [Impeller] Do not delete the GL object in a HandleGLES if the handle has a cleanup callback (flutter/flutter#183561)
2026-03-17 jason-simmons@users.noreply.github.com Encode source file patches as UTF-8 in the code formatter script (flutter/flutter#183761)
2026-03-17 82673815+gktirkha@users.noreply.github.com Fix widget inspector control layout and add safe area regression test (flutter/flutter#180789)
2026-03-17 43054281+camsim99@users.noreply.github.com Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)" (flutter/flutter#182522)
2026-03-17 1961493+harryterkelsen@users.noreply.github.com fix(web): fix crash in Skwasm when transferring non-transferable texture sources (flutter/flutter#183799)
2026-03-17 engine-flutter-autoroll@skia.org Roll Skia from dba893a44d7a to 84a180a1fa80 (7 revisions) (flutter/flutter#183803)
2026-03-17 brunocorona.alcantar@gmail.com Framework: Improve DropdownButton selectedItemBuilder assertion (flutter/flutter#183732)
2026-03-17 brunocorona.alcantar@gmail.com Add mainAxisAlignment to NavigationRail (flutter/flutter#183514)
2026-03-17 34871572+gmackall@users.noreply.github.com Update android triage process to not look at unassigned p1s every week (flutter/flutter#183805)
2026-03-17 30870216+gaaclarke@users.noreply.github.com Adds macos impeller new gallery transition perf test. (flutter/flutter#183802)
2026-03-17 1961493+harryterkelsen@users.noreply.github.com fix(web_ui): move prepareToDraw after raster to improve concurrency and stability (flutter/flutter#183791)
2026-03-17 rmacnak@google.com [build] Generate debug info for assembly. (flutter/flutter#183425)
2026-03-17 mdebbar@google.com [web] Fix occasional failure to find Chrome tab (flutter/flutter#183737)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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
okorohelijah pushed a commit to okorohelijah/packages that referenced this pull request Mar 26, 2026
…r#11281)

flutter/flutter@d117642...dd64978

2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from 2fb5fa71eb12 to f0a13e5efbad (2 revisions) (flutter/flutter#183830)
2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from ae3d36cb9e29 to 2fb5fa71eb12 (3 revisions) (flutter/flutter#183823)
2026-03-18 94012149+richardexfo@users.noreply.github.com Linux reuse sibling (flutter/flutter#183653)
2026-03-18 engine-flutter-autoroll@skia.org Roll Skia from 84a180a1fa80 to ae3d36cb9e29 (4 revisions) (flutter/flutter#183812)
2026-03-18 1961493+harryterkelsen@users.noreply.github.com fix(web): handle asynchronously disposed platform views (flutter/flutter#183666)
2026-03-17 87018443+mayanksharma9@users.noreply.github.com (Test cross-imports) Remove legacy Material import from sliver_constraints_test (flutter/flutter#183351)
2026-03-17 74057391+jhonathanqz@users.noreply.github.com Fix Android Studio pluginsPath when version is unknown (do not use 0.0) (flutter/flutter#182681)
2026-03-17 50643541+Mairramer@users.noreply.github.com Fixes animation glitch into bottom sheet (flutter/flutter#183303)
2026-03-17 ahmedsameha1@gmail.com Handle#6537 second grouped test (flutter/flutter#182529)
2026-03-17 ahmedsameha1@gmail.com Add a Clarification for the docs of suggestionsBuilder of SearchAnchor (flutter/flutter#183106)
2026-03-17 nate.w5687@gmail.com Remove obsolete null checks from style guide (flutter/flutter#181703)
2026-03-17 jason-simmons@users.noreply.github.com [Impeller] Do not delete the GL object in a HandleGLES if the handle has a cleanup callback (flutter/flutter#183561)
2026-03-17 jason-simmons@users.noreply.github.com Encode source file patches as UTF-8 in the code formatter script (flutter/flutter#183761)
2026-03-17 82673815+gktirkha@users.noreply.github.com Fix widget inspector control layout and add safe area regression test (flutter/flutter#180789)
2026-03-17 43054281+camsim99@users.noreply.github.com Reland "[Android] Add mechanism for setting Android engine flags via Android manifest (take 2)" (flutter/flutter#182522)
2026-03-17 1961493+harryterkelsen@users.noreply.github.com fix(web): fix crash in Skwasm when transferring non-transferable texture sources (flutter/flutter#183799)
2026-03-17 engine-flutter-autoroll@skia.org Roll Skia from dba893a44d7a to 84a180a1fa80 (7 revisions) (flutter/flutter#183803)
2026-03-17 brunocorona.alcantar@gmail.com Framework: Improve DropdownButton selectedItemBuilder assertion (flutter/flutter#183732)
2026-03-17 brunocorona.alcantar@gmail.com Add mainAxisAlignment to NavigationRail (flutter/flutter#183514)
2026-03-17 34871572+gmackall@users.noreply.github.com Update android triage process to not look at unassigned p1s every week (flutter/flutter#183805)
2026-03-17 30870216+gaaclarke@users.noreply.github.com Adds macos impeller new gallery transition perf test. (flutter/flutter#183802)
2026-03-17 1961493+harryterkelsen@users.noreply.github.com fix(web_ui): move prepareToDraw after raster to improve concurrency and stability (flutter/flutter#183791)
2026-03-17 rmacnak@google.com [build] Generate debug info for assembly. (flutter/flutter#183425)
2026-03-17 mdebbar@google.com [web] Fix occasional failure to find Chrome tab (flutter/flutter#183737)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC boetger@google.com,stuartmorgan@google.com 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
mboetger pushed a commit to mboetger/flutter that referenced this pull request Mar 26, 2026
…Android manifest (take 2)" (flutter#182522)

### Overview
Re-lands flutter#181632 which TLDR does
the following:

**Same old same old changes from original PR**
- Refactors all engine flags recognized by the Flutter Android embedding
(specifically those previously recognized by
[`FlutterShellArgs`](https://github.com/flutter/flutter/blob/4f5478cce38d837e14b7a032a12500d3fc0f1310/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java)
and all of those used to initialize the engine in `FlutterLoader`) into
a new class `FlutterEngineFlags` (`FlutterShellArgs` is kept for now to
maintain backwards compatibility; see
flutter#182153 for details)
- Adds the ability to set engine flags (that are recognized by
`FlutterEngineFlags`) via the manifest
- Adds warnings for developers that set engine flags via `Intent`s as
this will be disabled as part of
flutter#180686.
- Disallows debug/test only flags in release mode

**New changes/fixes**

> [!NOTE]
> This re-land was required because when previously submitted, it caused
b/483299339. I have confirmed that this bug has been fixed in this PR;
see go/flutter-android-setting-flags-in-manifest-perf-comparison for A/B
test results with the previous version of this PR
(flutter#181632) and commit
flutter@d6d4a07
of this PR.

- [Critical change] To fix the bug caught by b/483299339,
`--merged-platform-ui-thread` flag is added to `FlutterEngineFlag`s
- [Behavior change, not critical] To avoid more bugs like b/483299339,
`FlutterLoader` allows unrecognized flags specified by the command line
or `Intent` extras to be used to initialize the engine for now (same
behavior as before my original change but I plan to secure this in the
future; see flutter#182557)
- [Small refactor] To speed up manifest argument processing time,
`FlutterLoader` loops through all recognized `FlutterEngineFlag`s to
check if they are present in an application's manifest versus looping
through all metadata in an application's manifest and looking for
recognized `FlutterEngineFlag`s (small improvement for apps with large
manifests)
- [Small refactor] To speed up command line argument processing time,
`FlutterLoader` processes the `--aot-shared-library-name` flag in the
same loop as the other flags, reducing the number of loops
`ensureInitializationComplete` has to do (minimal improvement perf-wise
but kept it in because it's more readable to me)

### Full description
(Mostly copied from flutter#181632)

> [!NOTE]  
> This PR is based on conversation & feedback on
go/flutter-android-harden-engine-shell-arguments.

Adds a mechanism for setting Android engine flags via the manifest. If a
flag is specified on the command line and in manifest metadata, the
value specified on the command line will take precedence. Documentation
is added on this mechanism

Additionally, this PR removes the exposure of`--cache-sksl` command line
flag as per
[https://github.com/flutter/flutter/issues/140310#issuecomment-2708459007](https://www.google.com/url?q=https://github.com/flutter/flutter/issues/140310%23issuecomment-2708459007&sa=D&source=docs&ust=1761156167162464&usg=AOvVaw3a8ubXTtv3apknY2-P9dKe).

Additionally, this PR adds documentation for the only two supported ways
of setting engine flags moving forward -- via the command line or
manifest. The `Intent` mechanism will be removed when
flutter#180686 is completed (intended
to be a follow up to this PR).

As the unit tests in this PR only cover setting flags via manifest in
debug mode, I will follow up this PR with an integration test to test
that flags are appropriately respected/ignored in release mode. See
flutter#178383 for my currently working
but WIP draft.

Part of flutter#172553.

# Follow up work:

- [ ] **Migrate flags all un-migrated flags `FlutterEngineFlags`**
flutter#182852
- [ ] **Add integration test for this new added mechanism.** This will
land as an immediate follow-up to this PR. WIP in
flutter#182241.
- [ ] **Remove support for setting shell arguments via `Intent`.** This
task will be a follow up to this work + the integration test landing,
and will complete work for
flutter#172553. See
flutter#180686 for details.
- [ ] **Only allow known engine flags to be passed to the engine.** This
is more of a P2 but would be a nice additional security feature; see
flutter#182557.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Comment on lines +400 to +402
if (applicationMetaData.getBoolean(metadataKey, true)) {
shellArgs.add(arg);
}
Copy link
Copy Markdown
Member

@gmackall gmackall Apr 3, 2026

Choose a reason for hiding this comment

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

Isn't defaulting to true a behavior change for many of these flags?

IMPELLER_VULKAN_GPU_TRACING_DATA_KEY for example, defaulted to false before

Should we instead have a default value defined on the flag to fall back to? I.e. as part of the interface?

realmeylisdev added a commit to realmeylisdev/flutter that referenced this pull request Apr 5, 2026
Change the default in getBoolean(metadataKey, ...) from true to false,
restoring the pre-flutter#182522 behavior where a missing or malformed boolean
value in the AndroidManifest does not silently enable engine flags.

Fixes flutter#184581
github-merge-queue Bot pushed a commit that referenced this pull request Apr 8, 2026
…4631)

## Summary
- `FlutterLoader` parses Android manifest metadata for engine shell
flags, but `getBoolean(metadataKey, true)` defaults to `true` when the
value is missing or unparseable — accidentally enabling flags that
should be off
- Change the default from `true` to `false`, matching the pre-#182522
per-flag behavior where flags were disabled unless explicitly enabled

## Changes
-
`engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java`:
Changed `applicationMetaData.getBoolean(metadataKey, true)` to
`getBoolean(metadataKey, false)`

Fixes #184581

---------

Co-authored-by: Camille Simon <43054281+camsim99@users.noreply.github.com>
Co-authored-by: Camille Simon <camillesimon@google.com>
ahmedsameha1 pushed a commit to ahmedsameha1/flutter that referenced this pull request Apr 14, 2026
…Android manifest (take 2)" (flutter#182522)

### Overview
Re-lands flutter#181632 which TLDR does
the following:

**Same old same old changes from original PR**
- Refactors all engine flags recognized by the Flutter Android embedding
(specifically those previously recognized by
[`FlutterShellArgs`](https://github.com/flutter/flutter/blob/4f5478cce38d837e14b7a032a12500d3fc0f1310/engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/FlutterShellArgs.java)
and all of those used to initialize the engine in `FlutterLoader`) into
a new class `FlutterEngineFlags` (`FlutterShellArgs` is kept for now to
maintain backwards compatibility; see
flutter#182153 for details)
- Adds the ability to set engine flags (that are recognized by
`FlutterEngineFlags`) via the manifest
- Adds warnings for developers that set engine flags via `Intent`s as
this will be disabled as part of
flutter#180686.
- Disallows debug/test only flags in release mode

**New changes/fixes**

> [!NOTE]
> This re-land was required because when previously submitted, it caused
b/483299339. I have confirmed that this bug has been fixed in this PR;
see go/flutter-android-setting-flags-in-manifest-perf-comparison for A/B
test results with the previous version of this PR
(flutter#181632) and commit
flutter@d6d4a07
of this PR.

- [Critical change] To fix the bug caught by b/483299339,
`--merged-platform-ui-thread` flag is added to `FlutterEngineFlag`s
- [Behavior change, not critical] To avoid more bugs like b/483299339,
`FlutterLoader` allows unrecognized flags specified by the command line
or `Intent` extras to be used to initialize the engine for now (same
behavior as before my original change but I plan to secure this in the
future; see flutter#182557)
- [Small refactor] To speed up manifest argument processing time,
`FlutterLoader` loops through all recognized `FlutterEngineFlag`s to
check if they are present in an application's manifest versus looping
through all metadata in an application's manifest and looking for
recognized `FlutterEngineFlag`s (small improvement for apps with large
manifests)
- [Small refactor] To speed up command line argument processing time,
`FlutterLoader` processes the `--aot-shared-library-name` flag in the
same loop as the other flags, reducing the number of loops
`ensureInitializationComplete` has to do (minimal improvement perf-wise
but kept it in because it's more readable to me)

### Full description
(Mostly copied from flutter#181632)

> [!NOTE]  
> This PR is based on conversation & feedback on
go/flutter-android-harden-engine-shell-arguments.

Adds a mechanism for setting Android engine flags via the manifest. If a
flag is specified on the command line and in manifest metadata, the
value specified on the command line will take precedence. Documentation
is added on this mechanism

Additionally, this PR removes the exposure of`--cache-sksl` command line
flag as per
[https://github.com/flutter/flutter/issues/140310#issuecomment-2708459007](https://www.google.com/url?q=https://github.com/flutter/flutter/issues/140310%23issuecomment-2708459007&sa=D&source=docs&ust=1761156167162464&usg=AOvVaw3a8ubXTtv3apknY2-P9dKe).

Additionally, this PR adds documentation for the only two supported ways
of setting engine flags moving forward -- via the command line or
manifest. The `Intent` mechanism will be removed when
flutter#180686 is completed (intended
to be a follow up to this PR).

As the unit tests in this PR only cover setting flags via manifest in
debug mode, I will follow up this PR with an integration test to test
that flags are appropriately respected/ignored in release mode. See
flutter#178383 for my currently working
but WIP draft.

Part of flutter#172553.

# Follow up work:

- [ ] **Migrate flags all un-migrated flags `FlutterEngineFlags`**
flutter#182852
- [ ] **Add integration test for this new added mechanism.** This will
land as an immediate follow-up to this PR. WIP in
flutter#182241.
- [ ] **Remove support for setting shell arguments via `Intent`.** This
task will be a follow up to this work + the integration test landing,
and will complete work for
flutter#172553. See
flutter#180686 for details.
- [ ] **Only allow known engine flags to be passed to the engine.** This
is more of a P2 but would be a nice additional security feature; see
flutter#182557.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
github-merge-queue Bot pushed a commit that referenced this pull request Apr 15, 2026
…est (#182241)

Adds integration tests for setting engine flags via the manifest for
Flutter Android apps: #182522.
Technically, a continuation of
#178383.

Additionally:

1. Wires up `--test-flag` added in
#182522 so I can test command
line flag specification taking precedence over manifest flag
specification in debug mode only.
2. Fixes documentation/test bug of my previous claim that developers do
not need to specify a manifest metadata value for keys/flags that do not
take arguments in the format of `--flag=value` or
`--flag=value1,value2,...`. This is false; metadata requires a key-value
or key-resource pair (see [documentation
proof](https://developer.android.com/guide/topics/manifest/meta-data-element#:~:text=receiver%3E%0A%3Cservice%3E-,description%3A,-A%20name%2Dvalue)).
3. Refactors devicelab util method for adding metadata to the app
manifest to a central location.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: jesswrd <jesswon@google.com>
master-wayne7 pushed a commit to master-wayne7/flutter that referenced this pull request Apr 15, 2026
…est (flutter#182241)

Adds integration tests for setting engine flags via the manifest for
Flutter Android apps: flutter#182522.
Technically, a continuation of
flutter#178383.

Additionally:

1. Wires up `--test-flag` added in
flutter#182522 so I can test command
line flag specification taking precedence over manifest flag
specification in debug mode only.
2. Fixes documentation/test bug of my previous claim that developers do
not need to specify a manifest metadata value for keys/flags that do not
take arguments in the format of `--flag=value` or
`--flag=value1,value2,...`. This is false; metadata requires a key-value
or key-resource pair (see [documentation
proof](https://developer.android.com/guide/topics/manifest/meta-data-element#:~:text=receiver%3E%0A%3Cservice%3E-,description%3A,-A%20name%2Dvalue)).
3. Refactors devicelab util method for adding metadata to the app
manifest to a central location.

## Pre-launch Checklist

- [x] I read the [Contributor Guide] and followed the process outlined
there for submitting PRs.
- [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.
- [ ] All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel
on [Discord].

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

<!-- Links -->
[Contributor Guide]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview
[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/
[flutter/tests]: https://github.com/flutter/tests
[breaking change policy]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes
[Discord]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md
[Data Driven Fixes]:
https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md

---------

Co-authored-by: jesswrd <jesswon@google.com>
mbcorona pushed a commit to mbcorona/flutter that referenced this pull request Apr 15, 2026
…tter#184631)

## Summary
- `FlutterLoader` parses Android manifest metadata for engine shell
flags, but `getBoolean(metadataKey, true)` defaults to `true` when the
value is missing or unparseable — accidentally enabling flags that
should be off
- Change the default from `true` to `false`, matching the pre-flutter#182522
per-flag behavior where flags were disabled unless explicitly enabled

## Changes
-
`engine/src/flutter/shell/platform/android/io/flutter/embedding/engine/loader/FlutterLoader.java`:
Changed `applicationMetaData.getBoolean(metadataKey, true)` to
`getBoolean(metadataKey, false)`

Fixes flutter#184581

---------

Co-authored-by: Camille Simon <43054281+camsim99@users.noreply.github.com>
Co-authored-by: Camille Simon <camillesimon@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD d: docs/ flutter/flutter/docs, for contributors d: examples Sample code and demos engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team team-engine Owned by Engine team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants