Skip to content
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

Flutter build/run should be able to accept compile-time arguments #26638

Closed
c16a opened this issue Jan 16, 2019 · 8 comments
Closed

Flutter build/run should be able to accept compile-time arguments #26638

c16a opened this issue Jan 16, 2019 · 8 comments

Comments

@c16a
Copy link

@c16a c16a commented Jan 16, 2019

Consider the below scenario.

I am developing a global application with strikingly different feature sets across countries. So it is no more sensible to package all features into one app and enable or disable (with a flag, say) at runtime, as this would bloat up the app rapidly.

Also while development, I have my development, staging and production environments for which I would need to package and distribute the apps appropriately.

Something along the lines of the following would make sense

country=US env=DEV flutter build apk
country=UK env=STAGING flutter build ios

Currently, the multiple entry point approach suggested in #18377 (comment) won't scale when you have increasing number of dimensions (similar to a build matrix in CI/CD systems)

Are there any plans of implementing this? It is obvious that Flutter already supports having build-time flags (like --release etc). I have never contributed to Flutter as such (an avid user, though), but if add support for custom flags is something I can take up, I can do it.

@zoechi
Copy link
Contributor

@zoechi zoechi commented Jan 16, 2019

Sounds like you are looking for flavors
https://flutter.io/docs/deployment/flavors

Support is not perfect yet but usable with some tweaking here and there.

Loading

@c16a
Copy link
Author

@c16a c16a commented Jan 16, 2019

I am looking for a more "pure Dart" approach to doing this. I've come across the flavoring articles you that page mentions, and both of them require some tinkering with Xcode schemas and Android Gradle flavors.

I don't honestly think this is something that even needs to be offloaded to iOS and Android configurations.

country=US env=DEV flutter build apk
country=UK env=STAGING flutter build ios

We'll need to have a way to make them accessible to the Dart byte code.

The below works on DartVM (server side Dart), but would obviously not work when the app is deployed on iOS or Android.

var country = const System.fromEnvironment("country", default: "US")

Currently, achieving this would require a context switch from the Dart experience, go backward in time, deal with the Xcode/AndroidStudio hoolapalooza.

Loading

@mwinters-stuff
Copy link

@mwinters-stuff mwinters-stuff commented Jun 23, 2019

What we need is something like the androids "BuildConfig" class which can be set from the command line or/and from the pubspec.yaml. I would be keen on this.

Loading

@Feenposhleen
Copy link

@Feenposhleen Feenposhleen commented Oct 2, 2019

It would be nice to at least have some sort of build hook, where we could trigger an arbitrary Dart script before the app is compiled. Most issues could probably be worked around if this existed.

Being forced to use platform-specific flavoring is unnecessary cognitive load.

Loading

@Hixie Hixie removed this from the Stretch Goals milestone Jan 7, 2020
@Hixie Hixie added this to the New Stretch Goals milestone Jan 7, 2020
@jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Jan 9, 2020

Would be solved via #44483 , though this has more history so I'm leaving it open

Loading

@jmagman jmagman added this to Awaiting triage in Tools - command line usability review via automation Jan 11, 2020
@zanderso zanderso moved this from Awaiting triage to Engineer reviewed in Tools - command line usability review Feb 11, 2020
@zoechi
Copy link
Contributor

@zoechi zoechi commented Apr 10, 2020

--dart-define is available in flutter run, flutter build apk, flutter build ios, flutter drive. Can this be closed?

Loading

@jonahwilliams
Copy link
Member

@jonahwilliams jonahwilliams commented Apr 10, 2020

Yes! Thanks for the heads up @zoechi

Loading

@lock
Copy link

@lock lock bot commented Apr 25, 2020

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

Loading

@lock lock bot locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants