Currently I am using Flutter to build my application.
I have followed some guide on building different environments entry files:
https://iirokrankka.com/2018/03/02/separating-build-environments/
which create main_dev.dart
and main_prod.dart
.
Also I have learnt to build flavor for both iOS and Android:
https://medium.com/@salvatoregiordanoo/flavoring-flutter-392aaa875f36
which now I can use --flavor <FLAVOR>
in the command to build different flavor application.
Now I have encountered a problem when I try to combine two skills.
Below is what I would like to achieve:
development
flavor -> main_dev.dart
entry fileproduction
flavor -> main_prod.dart
entry file
in iOS side, I can target the entry file in .xcconfig file like following:
// ios/Flutter/development.xcconfig
#include "Generated.xcconfig"
FLUTTER_TARGET=lib/main_dev.dart
I know I can add -t lib/main_dev.dart
after flutter run
command.
However I would like to ask if there is any solution to set
the flutter target file in Android side inside flavor config?
Appreciate for any help.
I would like to ask if there is any solution to set the flutter target file in Android side inside flavor config?
I don't know the equal of FLUTTER_TARGET for Android flavor. I would to like to learn that too.
But, flutter run -t
is not the only option here. When you open a Flutter project (the root project) with Android Studio you will have a default run/debug configuration like below:
When you click Edit Configurations below screen will appear:
There you can set Build flavor and Dart entrypoint. Obviously, you can create multiple configurations for each flavor.
Reference: https://cogitas.net/creating-flavors-of-a-flutter-app/
So, that's a solution for Flutter in Android Studio. For VSCode, I have a workaround. I'm using -t parameter. But I have it automated by VSCode. Under .vscode/launch.json I have configurations like below:
"configurations": [
{
"name": "GoodOne",
"request": "launch",
"type": "dart",
"args": ["--flavor",
"good",
"-t",
"./lib/main-good.dart"
]
},
{
"name": "BadOne",
"request": "launch",
"type": "dart",
"args": ["--flavor",
"bad",
"-t",
"./lib/main-bad.dart"
]
}
]
With this, you can run your flavors by just pressing F5 and choose your config at the upper-left corner.
Again, this is not an exact answer to OP's question, but some workarounds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With