Adding run/debug configuration environment variables to a flutter project?


I am trying to add Environment Variables to my Run/Debug Configurations in my flutter project in Android Studio but the field is greyed out and I have no idea how to otherwise create environment variables. Any ideas how to add them either this way or in some other way?

A picture of my Run/Debug cConfigurations where the Environment variables are greyed out


A not-recommanded way to do this is to edit the flutter file(a script file: unix: bash, windows: bat). see here
I’m using linux and I have a problem of the application scale (since I’m using a hidpi screen), the probablly easist way to solve the problem is to set the environment variable GDK_SCALE=2. After some struggling, I finally edit my flutter source file like this:

#!/usr/bin/env bash
# Copyright 2014 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

export GDK_SCALE=2
# ---------------------------------- NOTE ---------------------------------- #
# Please keep the logic in this file consistent with the logic in the
# `flutter.bat` script in the same directory to ensure that Flutter continues

# ... [content omitted] ...

If you want to make environment variable change when starting a new project, please consider before launch option in RUN confiugration, you can run other configurations before run the current configuration. The ideal running sequence is running delete environment variable lines configuration(Shell Script type), before which execute(before launch) flutter run configuration, before which execute(before launch) add environment variable lines configuration(Shell Script type).(Total 3 configuration files which are linked in order) It should also show flutter debug window, since this option exists in the flutter run configuration.

Other ways I have tried:

  1. set global environment(all the application scale changed)
  2. modify android studio desktop file(android studio size changed)
  3. hack android studio run configuration (like $(export x=1) to execute command, however failed)

Answered By – zarkli

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published