Running Debug using Flutter Flavor?

Viewed 3543

I'm trying to run the debug mode on visual studio code (click "run and debug") for my flutter app, but when I do I'm facing the following issue:

The Xcode project defines schemes: release, private.

Exception: You must specify a --flavor option to select one of the available schemes.

So I have these two "flavours" but I'm not sure how to specify which to use. Normally, running the app through the terminal would require me to specify it as such: flutter run --flavor private but I'm not sure how to do the same for debug. Is there an equivalent command for debug mode?

Would appreciate some help, thanks in advance!

4 Answers

you have to add

"args":[ "-- flavor", "flavor_name" ]

in your .vscode > launch.json to obtain something like this:

 "configurations": [
        {
            "name": "flutterApp",
            "request": "launch",
            "type": "dart",
            "args": [
                "--flavor",
                "dev",
            ]
        },

then you need to launch the debugger from here selecting the correct configuration: enter image description here otherwise it will not work

This answer will only be what you're looking for if you created your flavors (and schemas) correctly (check this for reference: Flavors in Flutter by Flutter Explained channel) and if you are using android studio, since it is there were I solved it.

After having followed the video or any other correct explanation or set of steps, it is true that you cannot run the debugger nor have any of the DevTools attached if you run your app through a command. For example in my case, one of my flavors is named 'staging' so the command I ran would be:

flutter run --flavor staging -t lib/main_staging.dart

But by doing so, yes, you can run your app, but you won't see any of the previously mentioned tools attached. What I did (and this is the answer) is this:

enter image description here

and then added the additional args (in my case I wanted to run the 'staging' flavor or schema, as you already may have noticed) so:

enter image description here

After that, I got rid of this exception

Exception: You must specify a --flavor option to select one of the available schemes.

That is: the exception did not show again when hitting either one of these two buttons ('Run' or 'Debug'):

enter image description here

And that would be it. After that, I was able to see the debugger working as well as the DevTools.

In your launch.json file configurations, you can use this format for your iOS app to run:

  {
            "name": "production",
            "request": "launch",
            "type": "dart",
            "args": [
                "-t",
                "lib/main_prod.dart",
                "--flavor",
                "prod"
            ]
        }

yes , you have to add arguments in launch.json file configurations

"args":[ "-- flavor", "flavor_name" ]

N.B: you will get this json file in .vscode folder of your project

Related