You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
we should detect the user's PATH env var and use that when we shell out to the flutter tool #601
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.
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.
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().
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.
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.
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.
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.
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.
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.
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.
Activity
skybrian commentedon Jan 13, 2017
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.
devoncarew commentedon Jan 13, 2017
The flutter command has some functionality for that -
flutter config:skybrian commentedon Jan 14, 2017
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
skybrian commentedon Jan 14, 2017
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.
devoncarew commentedon Jan 14, 2017
+1!
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 thefluttertool, 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 thefluttercli tool or launch IntelliJ from the command-line.ScottPierce commentedon Jan 17, 2017
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 setenvin my~/.bash_profile. This allows me to run the same commands in IntelliJ terminal as I run in my normal terminal for osx.devoncarew commentedon Jan 19, 2017
Just for context, many users are hitting this on gitter.
skybrian commentedon Jan 19, 2017
What is gitter? How do I read more about this?
devoncarew commentedon Jan 19, 2017
gitter: https://gitter.im/flutter/flutter :)
Just providing context for the amount of impact of the issue -
skybrian commentedon Jan 20, 2017
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.
6 remaining items
skybrian commentedon Jan 31, 2017
Update: I don't think this is going to make the release.
skybrian commentedon Feb 1, 2017
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.
devoncarew commentedon Feb 1, 2017
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.
skybrian commentedon Feb 1, 2017
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.)
devoncarew commentedon Feb 1, 2017
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 deviceson the cli, but not in IntelliJ, a useful troubleshooting step is just to restart IntelliJ./cc @mit-mit
skybrian commentedon Feb 1, 2017
Looks like there is a known issue for Linux:
https://youtrack.jetbrains.com/issue/IDEA-146037
skybrian commentedon Feb 1, 2017
I filed a bug for the issue in EnvironmentUtil:
https://youtrack.jetbrains.com/issue/IDEA-167521
devoncarew commentedon Feb 1, 2017
👍
devoncarew commentedon Apr 3, 2017
Closing - the fix for this will happen upstream.
ohir commentedon Mar 5, 2018
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)