question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support envFile in launch configuration

See original GitHub issue

Is your feature request related to a problem? Please describe. My project uses a shared launch.json to facilitate development. When launching to an emulator, this is perfect. But when using a real device, I need to point my project to my local ip. Currently the way we do this is by editing the dart-define in our launch.json, then removing the edits before pushing to version control.

Describe the solution you’d like I’d like to be able to set an env like LOCAL_IP and reference that in a shared launch configuration. Currently the only way I can see to do this is by setting LOCAL_IP as an env in my launch config, which defeats the purpose. There are a few ways to attack this but the most straightforward seems to be supporting envFile.

Describe alternatives you’ve considered I have looked to see if VS Code supports user-specific launch configs (not ideal but would be fine as our configs rarely change) but I don’t think that they do. In theory you should have access to environment variables within the launch config but in practice this doesn’t seem to be the case.

Additional context Example launch config:

{
  "name": "Flutter: Launch Main App (android)",
  "request": "launch",
  "type": "dart",
  "program": "lib/main.dart",
  "args": [
    "--dart-define=my.api=http://10.0.2.2:5378/api"
  ]
}

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
DanTupcommented, Nov 14, 2022

FWIW in #4260 I was told about https://github.com/flutter/flutter/pull/108098 which adds support for reading dart-defines from a file. I don’t think it’s shipped in a stable Flutter yet, but when it does I suspect this will handle many of the use cases above without the need of an additional package.

2reactions
ghostcommented, Apr 6, 2021

@DanTup Yes. I can add environment variables to launch.json and git ignore it. But I would like to keep launch.json on git and only hide environment variables. For example my current configuration example is

// launch.json
{
"version": "0.2.0",
"configurations": [
{
      "name": "Development",
      "request": "launch",
      "type": "dart",
      "program": "./lib/main.dart",
      "showMemoryUsage": true,
      "env": {
        "CLIENT_SECRET": "*********",
        "API_URL": "https://1257fa8c220d.eu.ngrok.io/api/mobile-v2",
        "CLIENT_ID": 2,
        "BUSGNAGS_KEY": "*********"
      },
      "args": [
        "--dart-define=CLIENT_SECRET=${CLIENT_SECRET}",
       "--dart-define=CLIENT_ID=${CLIENT_ID}",
        "--dart-define=API_URL=${API_URL}",
       "--dart-define=BUSGNAGS_KEY=${BUSGNAGS_KEY}",
        "--flavor",
        "dev"
      ]
    },
//.... more configurations
]
}

The problem here is that my client environment variables are exposed. Which are different for teammates. Better solution would be provide envFile like in node.js app and use those variables on launch.json

// launch.json
{
"version": "0.2.0",
"configurations": [
{
      "name": "Development",
      "request": "launch",
      "type": "dart",
      "program": "./lib/main.dart",
      "showMemoryUsage": true,
      "envFile": "dev.env",
      "args": [
        "--dart-define=CLIENT_SECRET=${CLIENT_SECRET}",
       "--dart-define=CLIENT_ID=${CLIENT_ID}",
        "--dart-define=API_URL=${API_URL}",
       "--dart-define=BUSGNAGS_KEY=${BUSGNAGS_KEY}",
        "--flavor",
        "dev"
      ]
    },
//.... more configurations
]
}

dev.env

CLIENT_SECRET=*********
CLIENT_ID=2
API_URL=https://1257fa8c220d.eu.ngrok.io/api/mobile-v2"
BUSGNAGS_KEY=**********

With this setup dev.env could be git ignored. Another plus point for this is that we can use this same env file for other app for example if we using different tools for web development (react, vuejs)

Read more comments on GitHub >

github_iconTop Results From Across the Web

In VS Code-debugger, how do I use envFile in launch.json for ...
At first glance, it looks like your .env file isn't setup properly (as mentioned in the answer below). Here are some alternate options...
Read more >
Configure launch.json for C/C++ debugging in Visual Studio ...
A launch.json file is used to configure the debugger in Visual Studio Code. ... In order to support VS Code's Integrated Terminal with...
Read more >
How to Set up Environment Variables in "launch.json ...
Here is an example, you set the value in the environment block. { // Use IntelliSense to learn about possible attributes.
Read more >
Request for supporting .env file support from IDE for any Run ...
env file inside my project. I often work on Spring Boot or Tomcat Applications for most part of my work. Thus, if there...
Read more >
Visual Studio Code Can Do That? Environment Variables
... to add environment variables to launch configurations using an .env file. ... given you an extension to help with the env files...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found