Skip to content

we should detect the user's PATH env var and use that when we shell out to the flutter tool #601

Closed

Description

@devoncarew

In many OSes, when the user launches a GUI app from a launcher (OSX dock for example) the shell used is not necessarily the user's default shell. The env variables they had set up won't be visible to that GUI app. When we then shell out to something like the flutter tool, it won't be able to detect the location of the android deve tools, or other things that we'd find on a PATH.

See related (Dart) code here: https://github.com/dart-atom/atom.dart/blob/master/lib/node/process.dart#L190.

Activity

  1. modified the milestones: On Deck, on Jan 9, 2017
  2. skybrian commented on Jan 13, 2017

    @skybrian
    Contributor

    We should also handle the case where the Android dev tools aren't in the user's path at all.

    For me, they're not, since I tend to use bash aliases for command I run regularly, instead of adding them to my path. It looks like I did set ANDROID_HOME, though.

  3. self-assigned this
    on Jan 13, 2017
  4. devoncarew commented on Jan 13, 2017

    @devoncarew
    ContributorAuthor

    The flutter command has some functionality for that - flutter config:

    Usage: flutter config [arguments]
    -h, --help                  Print this usage information.
        --[no-]analytics        Enable or disable reporting anonymously tool usage statistics and crash reports.
        --gradle-dir            The gradle install directory.
        --android-studio-dir    The Android Studio install directory.
    
  5. skybrian commented on Jan 14, 2017

    @skybrian
    Contributor

    It looks like currently we don't use the PATH or environment variables at all. We find the Flutter SDK from the globally configured Dart SDK, under the assumption that the Dart SDK is in $FLUTTER_HOME/bin/cache/dart-sdk. If it's not, the getFlutterSdk() method returns null. Sometimes we handle that, other times it silently does nothing. [1]

    It seems like we want the Flutter SDK and the Dart SDK to be consistent, so we should help the user set their Dart SDK correctly, and then everything works? At least, we need to show an error when the current Dart SDK is not within a Flutter directory, explaining what to change it to.

    I'm not sure what the UI for this should look like. What are our options for displaying errors?

    (Also, the DartSdk plugin currently doesn't have a per-project Dart SDK setting, but I guess that is fixed in 2017.1 [2])

    [1] Code references:
    FlutterSdk.getGlobalFlutterSdk() uses DartSdk.getGlobalDartSdk() and getFlutterSdkByDartSdk().

    [2] https://youtrack.jetbrains.com/issue/WEB-20870

  6. skybrian commented on Jan 14, 2017

    @skybrian
    Contributor

    It looks like this should be the job of: SdkConfigurationNotificationProvider.createNotificationPanel().

    However, I set a breakpoint and changed the Dart SDK, and it didn't stop there.

  7. devoncarew commented on Jan 14, 2017

    @devoncarew
    ContributorAuthor

    At least, we need to show an error when the current Dart SDK is not within a Flutter directory, explaining what to change it to.

    +1!

    What are our options for displaying errors?

    Some good UI options are showing a toast (an IntelliJ Notification), and displaying a butter bar at the top of the current editor.

    Totally correct that IntelliJ isn't using PATH - we're locating relative to the sdk location. But when we shell out to the flutter tool, it using the PATH to discover other dev tools, like adb, the android sdk, ios tools, ... We want to set up PATH for the benefit of that tool, in order to make IntelliJ when launched from an app launcher similar to the behavior a user would see when they run the flutter cli tool or launch IntelliJ from the command-line.

  8. ScottPierce commented on Jan 17, 2017

    @ScottPierce

    If what's being described here is an inability to access certain environment variables in IntellIj, I've worked around this for years for Android by using launchctl setenv in my ~/.bash_profile. This allows me to run the same commands in IntelliJ terminal as I run in my normal terminal for osx.

    launchctl setenv PATH $PATH
    launchctl setenv JAVA_HOME $JAVA_HOME
    launchctl setenv ANDROID_HOME $ANDROID_HOME
    launchctl setenv FLUTTER_ROOT $FLUTTER_ROOT
    
  9. devoncarew commented on Jan 19, 2017

    @devoncarew
    ContributorAuthor

    Just for context, many users are hitting this on gitter.

  10. skybrian commented on Jan 19, 2017

    @skybrian
    Contributor

    What is gitter? How do I read more about this?

  11. devoncarew commented on Jan 19, 2017

    @devoncarew
    ContributorAuthor

    gitter: https://gitter.im/flutter/flutter :)

    Just providing context for the amount of impact of the issue -

  12. skybrian commented on Jan 20, 2017

    @skybrian
    Contributor

    I haven't reproduced this yet. I have a shell open with PATH='/usr/bin:/bin' and Flutter commands work fine so far, so I'm skeptical we need to set the PATH. If we do, it would be good to know which Flutter command cares about this.

  13. 6 remaining items

  14. skybrian commented on Jan 31, 2017

    @skybrian
    Contributor

    Update: I don't think this is going to make the release.

  15. skybrian commented on Feb 1, 2017

    @skybrian
    Contributor

    On second thought, I'm not sure there's anything to do.

    I was able to verify that ANDROID_HOME is not set within the IDEA Java process when run from the dock, but it is set by the time the 'flutter' command starts when I run "flutter doctor" from within IDEA. How does this happen? It appears that IDEA already implements a similar workaround for Macs.

    In the GeneralCommandLine class, there is a myParentEnvironmentType field which is set to ParentEnvironmentType.CONSOLE by default. When this is set, EnvironmentUtil.getEnvironmentMap() gets run. The ShellEnvReader class calls a helper script, which is at /Applications/IntelliJ\ IDEA\ CE.app/Contents/bin/printenv.py on my Mac.

    As long as we use GeneralCommandLine everywhere, and don't change the default, I think the environment should be set up correctly. If not, I need to figure out what our workaround code should do that IDEA's workaround code doesn't already do.

  16. devoncarew commented on Feb 1, 2017

    @devoncarew
    ContributorAuthor

    Thanks for investigating! Do you know if they have similar workaround code for linux? (but from looking here: https://github.com/JetBrains/intellij-community/blob/master/platform/util/src/com/intellij/util/EnvironmentUtil.java#L164, it seems like they do)

    I wonder what the user reports were running into? Perhaps they started IntelliJ, then configured their PATH? If I recall correctly, I think two separate github or gitter issues were resolved by closing IntelliJ and restarting it from the cli.

  17. skybrian commented on Feb 1, 2017

    @skybrian
    Contributor

    I think just restarting should do it. The environment is only read once and cached. (There is a static block at the top of the file.)

  18. devoncarew commented on Feb 1, 2017

    @devoncarew
    ContributorAuthor

    OK, thanks again for looking into this. I think we should add a FAQ or troubleshooting item about this on our docs; that the PATH is read once at startup, and if devices show up when running flutter devices on the cli, but not in IntelliJ, a useful troubleshooting step is just to restart IntelliJ.

    /cc @mit-mit

  19. skybrian commented on Feb 1, 2017

    @skybrian
    Contributor

    Looks like there is a known issue for Linux:
    https://youtrack.jetbrains.com/issue/IDEA-146037

  20. skybrian commented on Feb 1, 2017

    @skybrian
    Contributor

    I filed a bug for the issue in EnvironmentUtil:
    https://youtrack.jetbrains.com/issue/IDEA-167521

  21. devoncarew commented on Feb 1, 2017

    @devoncarew
    ContributorAuthor

    👍

  22. devoncarew commented on Apr 3, 2017

    @devoncarew
    ContributorAuthor

    Closing - the fix for this will happen upstream.

  23. ohir commented on Mar 5, 2018

    @ohir

    I was hit by this (and #634) with AS 3.0 and just installed official beta. There is NO mention of this glitch within documentation. For a quick workaround I set flutter config --android-studio-dir and --android-sdk manually as hinted by above discussion but it costed me finding #634 and this, both closed, issues.

    As there is bold advise on the install doc to run doctor twice the quick fix is possible:
    flutter doctor SHOULD update config using user's environment.

    --
    [✓] Flutter (Channel beta, v0.1.5, on Linux, locale pl_PL.utf8)
    [✓] Android toolchain - develop for Android devices (Android SDK 26.0.2)
    [✓] Android Studio (version 3.0)
    [✓] Connected devices (1 available)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions