someJoe121
someJoe121

Reputation: 379

Running Debug using Flutter Flavor?

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!

Upvotes: 12

Views: 22701

Answers (7)

SaumyadipDev
SaumyadipDev

Reputation: 275

Open your launch.json, create two different objects with different names like below:

"configurations": [
 {
   "name": "my-app sandbox",
   "request": "launch",
   "type": "dart",
   "args": ["--flavor", "sandbox"]
 },
 {
   "name": "my-app production",
   "request": "launch",
   "type": "dart",
   "args": ["--flavor", "production"]
},
]

And while running in debugger select the my-app production / my-app sandbox name, it will run without any issue.

Upvotes: 0

Sam Kuhns
Sam Kuhns

Reputation: 11

I encountered this, and had multiple schemes. In order to resolve it in addition to adding:

--flavor {scheme name}

to my run command, I also had to create a duplicate build configuration named

Debug-{scheme name}

You can do this by navigating to your project Runner in xCode, then Editor->Add Configuration-> Duplicate Debug (or your desired build),

then name in the format {Configuration}-{scheme name} Build Config Image

Upvotes: 1

eduardo-aop
eduardo-aop

Reputation: 1

In Xcode I had to create the missing scheme and go to Manage Schemes and mark as shared.

Upvotes: -1

Ivan Yoed
Ivan Yoed

Reputation: 4415

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.

Upvotes: 7

Serus
Serus

Reputation: 362

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

Upvotes: 6

Ian Wambai
Ian Wambai

Reputation: 223

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"
            ]
        }

Upvotes: 5

M Shakhawat Hossain
M Shakhawat Hossain

Reputation: 16

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

Upvotes: 0

Related Questions