Skip to content

[tool] Migrate BuildAarCommand to modular dependency injection - #192247

Merged
auto-submit[bot] merged 67 commits into
flutter:masterfrom
bkonyi:di/14c-build-aar
Sep 21, 2026
Merged

auto-submit[bot] merged 67 commits into
flutter:masterfrom
bkonyi:di/14c-build-aar

Conversation

@bkonyi

@bkonyi bkonyi commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

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 #192246
Compare: bkonyi/flutter@master...di/14c-build-aar

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`.
Migrate `BuildAarCommand` (`flutter build aar`) 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:45
@bkonyi
bkonyi removed the request for review from a team September 3, 2026 19:45
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 3, 2026
@bkonyi
bkonyi requested a review from mboetger September 3, 2026 19:45
@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 labels Sep 3, 2026
@github-actions github-actions Bot removed the team-android Owned by Android platform team label Sep 15, 2026
@bkonyi
bkonyi requested a review from dcharkes September 18, 2026 12:56
@bkonyi
bkonyi marked this pull request as ready for review September 18, 2026 12:56

@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 BuildAarCommand to accept its dependencies (AndroidBuilder, AndroidContext, BuildSystem, and ToolContext) directly through its constructor rather than relying on global context or individual fields. Corresponding updates were made to BuildCommand and the associated tests to pass these new parameters. Review feedback recommends adding documentation to the newly introduced public getters in BuildAarCommand to adhere to the style guide, and removing a redundant local logger variable that shadows an inherited member.

Comment thread packages/flutter_tools/lib/src/commands/build_aar.dart
Comment on lines 153 to 156
final Logger logger = toolContext.logger;
if (androidSdk == null) {
exitWithNoSdkMessage(analytics: analytics, logger: logger);
}

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.

medium

The local variable logger is redundant because logger is already inherited from FlutterCommand (via BuildSubCommand). Removing it simplifies the code and avoids shadowing the inherited member.

    if (androidSdk == null) {
      exitWithNoSdkMessage(analytics: analytics, logger: logger);
    }
References
  1. Suggest simplification and refactoring: Assess whether the code can be made simpler or refactored to enhance readability and maintainability. (link)

@flutter-dashboard

Copy link
Copy Markdown

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #192247 at sha f5bf437

@flutter-dashboard flutter-dashboard Bot added the will affect goldens Changes to golden files label Sep 18, 2026
''');

final BuildCommand command = createFakeBuildCommand(
androidSdk: FakeAndroidSdk(),

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.

nice!

final Directory dotAndroidDir = fs.directory('.android')..createSync(recursive: true);
dotAndroidDir.childFile('gradlew').createSync();

processManager.addCommands(<FakeCommand>[

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.

why dont we need this anymore?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

At this line we were still accessing context.get<AndroidBuilder>() (androidBuilder is a getter defined on BuildCommand) instead of the FakeAndroidBuilder passed to BuildAarCommand. Since we're not longer using a "real" instance, we don't have these process invocations anymore.

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.

Ah and using a real instance or not doesn't matter for this test. gotcha.

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. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants