Skip to content

Expose the app's build name and number as compile-time constants#187935

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Ortes:expose-build-name-defines
Jul 8, 2026
Merged

Expose the app's build name and number as compile-time constants#187935
auto-submit[bot] merged 5 commits into
flutter:masterfrom
Ortes:expose-build-name-defines

Conversation

@Ortes

@Ortes Ortes commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The tool already injects FLUTTER_VERSION, FLUTTER_CHANNEL, framework/engine revisions (exposed as FlutterVersion) and FLUTTER_APP_FLAVOR (exposed as appFlavor) as dart-defines. The application's own version: from pubspec.yaml is the one missing field, even though the tool already parses it (FlutterManifest.buildName/buildNumber) and embeds it into version.json, Info.plist and build.gradle on every build.

Without it, the running version is unknowable on the web: version.json is fetched from the server at runtime, so a stale cached client reports the freshly deployed version instead of its own, and version gates / update prompts built on package_info_plus silently fail for exactly the users they exist for (fluttercommunity/plus_plugins#2675).

This PR:

  • injects FLUTTER_BUILD_NAME and FLUTTER_BUILD_NUMBER (the app's pubspec version, overridable via --build-name/--build-number) in FlutterCommand.getBuildInfo, following the FLUTTER_APP_FLAVOR pattern including its reserved-name guards;
  • exposes them as appBuildName / appBuildNumber constants in package:flutter/services.dart (new src/services/app_version.dart, same style as flavor.dart / flutter_version.dart);
  • adds tool tests (injection from pubspec, no injection without a version, environment/dart-define collision guards) and framework tests.

Like all String.fromEnvironment constants, these are tree-shaken when unreferenced, so nothing ships in the binary unless the app reads them.

package_info_plus is ready to consume these defines (fluttercommunity/plus_plugins#3874), which would make the fix transparent for the ecosystem. A companion proposal for the pure-Dart side (dart compile, servers/CLIs) is dart-lang/sdk#38855 — neither subsumes the other, since Flutter does not build through dartdev.

Fixes #187934

Pre-launch Checklist

@github-actions github-actions Bot added tool Affects the "flutter" command-line tool. See also t: labels. framework flutter/packages/flutter repository. See also f: labels. labels Jun 12, 2026

@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 introduces 'appBuildName' and 'appBuildNumber' constants to the services library, allowing applications to access their build name and build number at runtime. These values are injected into 'dartDefines' during the build process, with validation to prevent users from manually overriding them. Feedback suggests refining the validation logic when checking existing 'dartDefines' to avoid false positives on custom variables that share a prefix with the framework-defined build variables.

Comment thread packages/flutter_tools/lib/src/runner/flutter_command.dart Outdated
Ortes added a commit to Fullphysio/plus_plugins that referenced this pull request Jun 12, 2026
…allbacks

PackageInfoEnvironment now resolves the web version from, in order:
PACKAGE_INFO_PLUS_VERSION (explicit), FLUTTER_BUILD_NAME
(flutter/flutter#187935, injected by flutter_tools like
FLUTTER_APP_FLAVOR), and dart.package.version (dart-lang/sdk#38855).
Once either upstream proposal lands, apps need no configuration at all.
Ortes added a commit to Fullphysio/plus_plugins that referenced this pull request Jun 12, 2026
…allbacks

PackageInfoEnvironment now resolves the web version from, in order:
PACKAGE_INFO_PLUS_VERSION (explicit), FLUTTER_BUILD_NAME
(flutter/flutter#187935, injected by flutter_tools like
FLUTTER_APP_FLAVOR), and dart.package.version (dart-lang/sdk#38855).
Once either upstream proposal lands, apps need no configuration at all.
@Ortes Ortes force-pushed the expose-build-name-defines branch from 58b0f53 to ebcb817 Compare June 15, 2026 11:23
@bkonyi bkonyi added team-framework Owned by Framework team team-tool Owned by Flutter Tool team labels Jun 16, 2026

@bkonyi bkonyi 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.

This generally LGTM with some minor comments. We'll also need someone from the framework to sign off on the changes to packages/flutter/.

Comment thread packages/flutter_tools/lib/src/runner/flutter_command.dart Outdated
Comment thread packages/flutter_tools/lib/src/runner/flutter_command.dart Outdated
@github-actions github-actions Bot removed the team-tool Owned by Flutter Tool team label Jun 18, 2026
@Ortes Ortes force-pushed the expose-build-name-defines branch 2 times, most recently from 29b3949 to 72d3f13 Compare June 25, 2026 16:14
@justinmc justinmc requested a review from loic-sharma June 30, 2026 22:25
Comment thread packages/flutter/test/services/app_version_test.dart
@loic-sharma

Copy link
Copy Markdown
Member

Hello @Ortes, apologies for the late review! This looks good to me, but let's add an integration test for the framework side (see this comment).

Also, could you rebase these changes off the latest master branch?

Once that's done, I'll kick off tests and get this landed! :)

@Ortes Ortes force-pushed the expose-build-name-defines branch from 72d3f13 to d3a9a37 Compare June 30, 2026 23:16
loic-sharma
loic-sharma previously approved these changes Jul 1, 2026

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the wonderful contribution!

@loic-sharma loic-sharma added the CICD Run CI/CD label Jul 1, 2026
@Ortes

Ortes commented Jul 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the wonderful contribution!

Thanks for your amazing maintainer work!

@Ortes

Ortes commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

CI was red on the Linux and Mac_arm64 tool_tests_commands shards. Exposing FLUTTER_BUILD_NAME / FLUTTER_BUILD_NUMBER prepends two entries to the -Pdart-defines argument passed to Gradle, which broke the hardcoded command expectations in build_apk_test.dart (6 tests) and build_aar_test.dart (1 test).

Fixed in ab03bcb by adding the two defines to those expected dart-defines maps. The shard passes locally now.

@Ortes Ortes force-pushed the expose-build-name-defines branch from ab03bcb to 2bb1531 Compare July 2, 2026 12:22
Ortes added 2 commits July 3, 2026 10:04
Verifies that a pubspec version is exposed via the appBuildName and appBuildNumber constants when running flutter test, mirroring the existing default_flavor_test.dart pattern.
…rt-defines

FLUTTER_BUILD_NAME and FLUTTER_BUILD_NUMBER are now injected into the
dart-defines passed to Gradle, which broke the hardcoded expectations in
these command tests.
@bkonyi bkonyi added the CICD Run CI/CD label Jul 3, 2026
@Ortes Ortes force-pushed the expose-build-name-defines branch from 2bb1531 to 2688822 Compare July 3, 2026 18:37
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Jul 3, 2026
@Ortes Ortes requested a review from loic-sharma July 3, 2026 19:23

@loic-sharma loic-sharma left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@loic-sharma loic-sharma added CICD Run CI/CD autosubmit Merge PR when tree becomes green via auto submit App labels Jul 7, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 8, 2026
@auto-submit

auto-submit Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/187935, because - The status or check suite Linux web_skwasm_tests_0 has failed. Please fix the issues identified (or deflake) before re-applying this label.

@Ortes

Ortes commented Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

The Linux web_skwasm_tests_0 failure looks like an infra flake rather than an issue with this PR:

  • The build (8676892560572427201) ended as INFRA_FAILURE with a timeout, not a test failure.
  • The log shows 2,224 tests passing in under 3 minutes, then the runner goes silent while loading test/cupertino/text_field_restoration_test.dart until the build timeout cancelled the step ~40 minutes later. No error, exception, or failing test appears anywhere in the log.
  • The test added by this PR (test/services/app_version_test.dart) is not in shard 0's test list, and the sibling shard Linux web_skwasm_tests_1 passed.

Re-running the shard should clear it.

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 8, 2026
@auto-submit auto-submit Bot added this pull request to the merge queue Jul 8, 2026
Merged via the queue into flutter:master with commit 8741012 Jul 8, 2026
177 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels. team-framework Owned by Framework 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.

Expose the app's build name/number as compile-time constants (complete the FlutterVersion/appFlavor pattern)

3 participants