[tool] Migrate BuildApkCommand and Android build toolchain to modular dependency injection - #190776
Conversation
a9748ac to
9e45bc1
Compare
…endency injection
9e45bc1 to
fdb15cd
Compare
There was a problem hiding this comment.
Code Review
This pull request refactors BuildCommand and its subcommands (BuildAarCommand, BuildApkCommand, and BuildAppBundleCommand) to explicitly inject dependencies like AndroidContext and ToolContext instead of relying on global variables, and updates associated tests to run without context. The review feedback highlights a few areas for improvement: avoiding the use of OutputPreferences.test() as a fallback in production code, caching the project getter in BuildAarCommand and BuildAppBundleCommand to prevent redundant file system I/O and object creation, and ensuring that casting terminal to AnsiTerminal does not discard custom mock implementations in tests.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors BuildCommand and its subcommands (BuildAarCommand, BuildApkCommand, and BuildAppBundleCommand) to support dependency injection of ToolContext, AndroidContext, and AndroidBuilder instead of relying on global variables, enabling hermetic testing without context overrides. A critical bug was identified in BuildCommand where omitting the androidBuilder argument during instantiation in production causes it to default to null, resulting in Android builds silently doing nothing. The feedback suggests falling back to context.get() when the injected builder is null.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the Android build commands (BuildAarCommand, BuildApkCommand, and BuildAppBundleCommand) to accept their dependencies directly through their constructors instead of relying on global context, enabling them to be tested using testWithoutContext. Feedback suggests caching the _featureFlags getter in FlutterCommand to prevent redundant object allocations and improve performance.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request refactors the build command infrastructure in the Flutter tools by introducing ToolContext and AndroidContext to centralize dependencies. It updates BuildCommand and its subcommands (BuildAarCommand, BuildApkCommand, BuildAppBundleCommand) to use these contexts, reducing redundant parameter passing. Additionally, it cleans up test code by introducing fake contexts and updates the exitWithNoSdkMessage utility to accept optional dependencies. The review feedback suggests further simplifying the command constructors and getters by leveraging the androidContext property to access androidSdk and avoiding unnecessary terminal downcasts.
There was a problem hiding this comment.
Code Review
This pull request refactors the Android build tooling, specifically AndroidGradleBuilder and BuildApkCommand, to accept context and builder dependencies via their constructors instead of relying on global variables. This change improves testability, and corresponding unit tests have been added or updated. Feedback on the changes notes a regression in gradle_utils.dart where the error parameter was omitted from the Event.flutterBuildInfo telemetry call, which should be restored.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…lchain' into di/14-android-build-and-toolchain
dcharkes
left a comment
There was a problem hiding this comment.
reapproving after rebase/merge.
…lutter#192246) ## 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 flutter#190776 Compare: bkonyi/flutter@di/14-android-build-and-toolchain...di/14b-build-appbundle Part of flutter#47161 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Summary
Part 14 of the modular dependency injection migration.
BuildApkCommand(flutter build apk) and shared Android toolchain components to modular constructor dependency injection:AndroidBuilderinBuildCommandandAndroidGradleBuilder, eliminating ambientglobals.dartandcontext.get<AndroidBuilder>()fallbacks.AnalyticsandLoggerinexitWithNoSdkMessage.BuildAppBundleCommandandBuildAarCommandmigrations to stacked follow-up PRs (#190778 /di/14b-build-appbundleanddi/14c-build-aar).testWithoutContextwhere applicable.Part of #188471