-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Reverts "Support conditional bundling of assets based on --flavor"
#139787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
auto-submit
merged 1 commit into
master
from
revert_016eb85177c9cef03f62c2ec2ad797398952e310
Dec 8, 2023
Merged
Reverts "Support conditional bundling of assets based on --flavor"
#139787
auto-submit
merged 1 commit into
master
from
revert_016eb85177c9cef03f62c2ec2ad797398952e310
Dec 8, 2023
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fluttergithubbot
approved these changes
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Dec 8, 2023
engine-flutter-autoroll
added a commit
to engine-flutter-autoroll/packages
that referenced
this pull request
Feb 16, 2024
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Reverts #132985
Initiated by: christopherfujino
This change reverts the following previous change:
Original Description:
Provides support for conditional bundling of assets through the existing
--flavoroption forflutter buildandflutter run. Closes #21682. Resolves #136092Change
Within the
assetssection pubspec.yaml, the user can now specify one or moreflavorsthat an asset belongs to. Consider this example:With this pubspec,
flutter run --flavor vanillawill not includeassets/strawberry/ice-cream.pngin the build output.flutter run --flavor strawberrywill not includeassets/vanilla/ice-cream.png.flutter runwill only includeassets/normal-asset.png.Open questions
--flavorsupport (Android, iOS, and (implicitly) MacOS)? This PR currently only enables this feature for officially supported platforms.Design thoughts, what this PR does not do, etc.
This does not provide an automatic mapping/resolution of asset keys/paths to others based on flavor at runtime.
The implementation in this PR represents a simplest approach. Notably, it does not give Flutter the ability to dynamically choose an asset based on flavor using a single asset key. For example, one can't use
Image.asset('config.json')to dynamically choose between different "flavors" ofconfig.json(such asdev-flavor/config.jsonorprod-flavor/config.json). However, a user could always implement such a mechanism in their project or in a library by examining the flavor at runtime.When multiple entries affect the same file and 1) at least one of these entries have a
flavorslist provided and 2) these lists are not equivalent, we always consider the manifest to be ambiguous and will throw aToolExit.Details
For example, these manifests would all be considered ambiguous:See this review comment thread for the full story on how I arrived at this decision.
This does not support Android's multidimensional flavors feature (in an intuitive way)
Details
Conder this excerpt from a Flutter project's android/app/build.gradle file:
android { // ... flavorDimensions "mode", "api" productFlavors { free { dimension "mode" applicationIdSuffix ".free" } premium { dimension "mode" applicationIdSuffix ".premium" } minApi23 { dimension "api" versionNameSuffix "-minApi23" } minApi21 { dimension "api" versionNameSuffix "-minApi21" } } }In this setup, the following values are valid
--flavorare validfreeMinApi21,freeMinApi23,premiumMinApi21, andpremiumMinApi23. We call these values "flavor combinations". Consider the following from the Android documentation1:This feature will not behave in this way. If a user utilizes this feature and also Android's multidimensional flavors feature, they will have to list out all flavor combinations that contain the flavor they want to limit an asset to:
This is mostly due to a technical limitation in the hot-reload feature of
flutter run. During a hot reload, the tool will try to update the asset bundle on the device, but the tool does not know the flavors contained within the flavor combination (that the user passes to--flavor). Gradle is the source of truth of what flavors were involved in the build, andflutter runcurrently does not access to that information since it's an implementation detail of the build process. We could bubble up this information, but it would require a nontrivial amount of engineering work, and it's unclear how desired this functionality is. It might not be worth implementing.See https://flutter.dev/go/flavor-specific-assets for the (outdated) design document.
///).Footnotes
https://developer.android.com/build/build-variants#flavor-dimensions ↩