Sitelet https://github.com/flutter/flutter/pull/192246
Skip to content

[tool] Migrate BuildAppBundleCommand to modular dependency injection - #192246

Merged
auto-submit[bot] merged 48 commits into
flutter:masterfrom
bkonyi:di/14b-build-appbundle
Sep 17, 2026
Merged

auto-submit[bot] merged 48 commits into
flutter:masterfrom
bkonyi:di/14b-build-appbundle

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Part 14b of the modular dependency injection migration.

Migrates BuildAppBundleCommand (flutter build appbundle) to modular dependency injection with ToolContext and AndroidContext, removing direct dependencies on globals.dart.

Stacked on #190776
Compare: bkonyi/flutter@di/14-android-build-and-toolchain...di/14b-build-appbundle

Part of #47161

Extract Logger, Terminal, FileSystem, and Platform from ToolContext using object pattern destructuring for diff reduction in build_apk, build_appbundle, and build_aar.
…in Android build commands

Ensure AndroidBuilder is required and non-nullable in BuildAarCommand, BuildApkCommand, and BuildAppBundleCommand. Construct effective AndroidGradleBuilder in BuildCommand if not injected. Update tests to remove context.get<AndroidBuilder>() and context.get<Analytics>().
…ate fallback globals

Require non-nullable `AndroidBuilder` parameter in `BuildCommand` to eliminate
fallback `AndroidGradleBuilder` construction within the command body. Require
`Analytics` and `Logger` in `exitWithNoSdkMessage` to remove ambient `globals`
fallback references. Simplify test runners across permeable Android build tests.
…separate PRs

Narrow scope of PR 14 to `AndroidGradleBuilder` constructor DI, `exitWithNoSdkMessage` refactoring, non-nullable `AndroidBuilder` in `BuildCommand`, and `BuildApkCommand` migration.
Migrate `BuildAppBundleCommand` (`flutter build appbundle`) to modular dependency injection with `ToolContext`, `AndroidContext`, `BuildSystem`, and `AndroidBuilder`, removing direct dependencies on `globals.dart`.
@bkonyi
bkonyi requested review from a team as code owners September 3, 2026 19:43
@bkonyi
bkonyi requested review from camsim99 and removed request for a team September 3, 2026 19:43
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 3, 2026
@bkonyi bkonyi added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 3, 2026
@github-actions github-actions Bot added a: desktop Running on desktop team-android Owned by Android platform team team-ios Owned by iOS platform team labels Sep 3, 2026
@github-actions github-actions Bot removed the team-android Owned by Android platform team label Sep 15, 2026
@bkonyi
bkonyi marked this pull request as ready for review September 16, 2026 15:50

@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 refactors BuildAppBundleCommand to inject dependencies like AndroidBuilder, AndroidContext, BuildSystem, and ToolContext instead of relying on global variables, and introduces new unit tests. The review feedback suggests refactoring to avoid duplication by moving the toolContext override and the targetFile getter to the base BuildSubCommand class, and recommends accessing _androidContext.androidSdk directly rather than through the testing-annotated getter.

Comment thread packages/flutter_tools/lib/src/commands/build_appbundle.dart
Comment thread packages/flutter_tools/lib/src/commands/build_appbundle.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/build_appbundle.dart Outdated
@bkonyi
bkonyi requested a review from dcharkes September 16, 2026 18:59

@dcharkes dcharkes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

I remember the discussions around globals when I first started contributing and was forced to plumb deps through constructors and function calls instead. But indeed it makes testing much easier. (We do so extensively by mocking the package:hooks_runner as well.)

High level question: Is this just cleanup, or do we have another overarching goal as well?

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
@bkonyi

bkonyi commented Sep 17, 2026

Copy link
Copy Markdown
Contributor Author

LGTM!

I remember the discussions around globals when I first started contributing and was forced to plumb deps through constructors and function calls instead. But indeed it makes testing much easier. (We do so extensively by mocking the package:hooks_runner as well.)

High level question: Is this just cleanup, or do we have another overarching goal as well?

They've been a thorn in our side for years now, but we've never been able to justify the engineering hours to actually perform the migration work. Agents have made this much easier :)

This is "cleanup" in the sense that it's part of a project health initiative to remove this global state, and it should help with some future decoupling work.

@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 17, 2026
Merged via the queue into flutter:master with commit 2d3333f Sep 17, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 17, 2026
pull Bot pushed a commit to Mattlk13/flutter that referenced this pull request Sep 21, 2026
…er#192247)

## Summary

Part 14c of the modular dependency injection migration.

Migrates `BuildAarCommand` (`flutter build aar`) to modular dependency
injection with `ToolContext` and `AndroidContext`, removing direct
dependencies on `globals.dart`.

Stacked on flutter#192246
Compare:
bkonyi/flutter@master...di/14c-build-aar

Part of flutter#47161

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants