Skip to content

Support different set of assets depending on platform and flavor parameters - #25487

Closed
sestegra wants to merge 14 commits into
flutter:masterfrom
sestegra:21682
Closed

sestegra wants to merge 14 commits into
flutter:masterfrom
sestegra:21682

Conversation

@sestegra

@sestegra sestegra commented Dec 17, 2018 •

Copy link
Copy Markdown

Need to expose flavor parameters to support different set of assets depending on --flavor xxx (#21682)

Need to expose platform parameters to support different set of assets dependeint on --target-platform xxx (#8230)

@zoechi zoechi added tool Affects the "flutter" command-line tool. See also t: labels. a: assets Packaging, accessing, or using assets labels Dec 18, 2018
@sestegra sestegra changed the title Expose flavor parameters to buildAssets() function Expose platform and flavor parameters to buildAssets function Dec 18, 2018
@sestegra sestegra changed the title Expose platform and flavor parameters to buildAssets function Support different set of assets depending on platform and flavor parameters Dec 18, 2018
@sestegra

Copy link
Copy Markdown
Author

Manifest files are loaded in following order

  • pubspec.yaml
  • assets.yaml
  • assets-<platform>.yaml
  • assets-<flavor>.yaml (only for local package)
  • assets-<platform>-<flavor>.yaml (only for local package)

assets, fonts and use-material-design parameters are overridden at each loaded file.
When an assets file is not present, the next one is loaded without overriding parameters from previous steps.

Assets file format is the same as pubspec.yaml.

@sestegra

sestegra commented Dec 18, 2018 •

Copy link
Copy Markdown
Author

TODO

  • YamlMap is immutable in _createFromPathWithAssets from packages/flutter_tools/lib/src/flutter_manifest.dart
  • Add --flavor and --target-platform options in packages/flutter_tools/gradle/flutter.gradle
  • Add --flavor and --target-platform options in packages/flutter_tools/bin/xcode_backend.sh

@sestegra sestegra changed the title Support different set of assets depending on platform and flavor parameters WIP - Support different set of assets depending on platform and flavor parameters Dec 19, 2018
@sestegra sestegra changed the title WIP - Support different set of assets depending on platform and flavor parameters Support different set of assets depending on platform and flavor parameters Dec 19, 2018
@sestegra

Copy link
Copy Markdown
Author

See sample project here:
https://github.com/sestegra/flutter_assets_flavors

Feel free to comment.

@tvolkert

Copy link
Copy Markdown
Contributor

@sestegra thanks for the proposal! I think before we land a change to our project structure and manifest files, we need to think more about all the use cases we plan to support and come up with a comprehensive way to do so. For example, we're likely going to want to support asset resolution based on:

  • locale
  • screen size / pixel density
  • platform
  • text direction
  • flavor

See also the discussion in #16015

Since you've obviously thought about this problem some, would you be willing to write up a proposal for how to tackle this more comprehensively (in prose, not in code) as an informal RFC? We're thinking about how to formalize a Flutter RFC process, but we don't have one yet 😄

@tvolkert tvolkert added the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Jan 30, 2019
@sestegra

sestegra commented Jan 30, 2019 •

Copy link
Copy Markdown
Author

This pull request was more a POC than an implementation (missing tests...)

I'm quite busy right now, but I took some time to initiate the request.
So, I won't be able to drive or follow this RFC.

I guess the RFC process could be managed in a more collaborative way: I mean outside this thread.

Basically, it's only a draft from scratch and it could be a starting point to other contributors to collaborate.

Assets Management and flavoring RFC

Assets Management and flavoring References

Issues

Articles and projects

Localization

Device screen size / pixel density / form-factor

Use cases

Assets like images, text or raw data could be diversified regarding many use cases, some of these use cases are presented below.

Debug / Staging / Production

In order to install debug, staging and/or production flavor of your application on the same device, they need to have different ApplicationId/BundleId. For instance, to avoid public leakage of production assets, it could be useful to have different assets per flavor. Debug/Staging assets could be only placeholders or mocked data.

Free / Paid version

Free and paid version could differ in the assets they need.

Localization / Text direction

Text and graphics containing references to objects, actions or ideas which, in a given culture, may be subject to misinterpretation or viewed as insensitive.

Security / Compliance

For security and/or compliance reasons, some assets could not be exposed before production, but should be tested with placeholders or mocked data.

Device screen size / Pixel density

Assets density is already addressed by current Flutter assets management.

Platform / Layout

Flutter is currently supporting android, iOS and Fuschia platform.
Regarding last announcements, Flutter would support more platform like Web and Desktop.
In that perspective, it would be preferable to select assets per platform.
In fact, different factors could influence the assets: like User eXperience, device screen size, pixel density and dynamic layout (resize on multi-tasking and rotation for instance).

Possible variables

Regarding previous use cases, the following variables should be taken into account to develop assets management and flavoring:

  • Embedded vs downloaded assets
  • Same vs different ApplicationId/BundleId
  • Flutter platform, flavor and target options

Possible solutions

  • Propagate flavor option in all Flutter tools
    It's one of the goal of this pull request
  • Manage assets from possible variables
    This pull request only addresses platform and flavor
  • Add a tool to manage flavors from command line, to ease the flavor management with Flutter (i.e. no manual edition of configuration files)
    I developed a POC flutter-flavor. It's only Bash based, because XCode file parsing is a mess.

@zoechi

zoechi commented Jan 30, 2019

Copy link
Copy Markdown
Contributor

#5813 is also an interesting related requirement

@robinbonnes

Copy link
Copy Markdown

This would be a great advantage for Flutter. Any updates?

@christopherfujino christopherfujino removed the waiting for response The Flutter team cannot make further progress on this issue until the original reporter responds label Apr 4, 2019
@jonahwilliams

Copy link
Copy Markdown
Contributor

Working through our backlog:

This is a good proposal, and I agree that it would be great to have both #8230 and #21682 supported.

I don't think this PR is the way to go about doing so however. I see a lot of opportunities where we could accidentally end up caching the wrong assets, failing to delete older assets, or not copying them as needed. It may work incidentally as we disabled most build caching, but as I work to re-enabled this in the next few months it will become another issue.

The second concern is that with the current build system this will lead to more build invalidations than necessary. For example, switching flavors would cause build/flutter_assets to get overwritten, and so switching back would lose the cache.

Finally, this PR has no tests. We simply cannot accept major feature additions without tests. I'm going to close this PR , but I would love to solve it differently this year.

@talregev

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: assets Packaging, accessing, or using assets tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants