flutter/flutter-intellij

Use IntelliJ proxy settings when running flutter/pub commands

Fredro opened this issue · 14 comments

Steps to Reproduce

Create new project, go through the setup. It tries to run "packages get", retries a lot. Close program because getting nowhere. Open studio again select project. Studio says "package get" not run, run now. I run it, and the result below

C:\src\flutter\bin\flutter.bat --no-color packages get
Running "flutter packages get" in flutter_app...                
Could not resolve URL "https://pub.dartlang.org".
pub get failed (69) -- attempting retry 1 in 1 second...

Go into Settings, and HTTP Proxy settings, automatic proxy conf is selected. Check connection is working when entering "https://pub.dartlang.org".

Version info

[√] Flutter (Channel stable, v1.0.0, on Microsoft Windows [Version 10.0.16299.785], locale sv-SE)
    • Flutter version 1.0.0 at C:\src\flutter
    • Framework revision 5391447fae (5 days ago), 2018-11-29 19:41:26 -0800
    • Engine revision 7375a0f414
    • Dart version 2.1.0 (build 2.1.0-dev.9.4 f9ebf21297)

[√] Android toolchain - develop for Android devices (Android SDK 28.0.3)
    • Android SDK at C:\Users\xxx\AppData\Local\Android\sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)
    • All Android licenses accepted.

[√] Android Studio (version 3.2)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 31.1.1
    • Dart plugin version 181.5656
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1136-b06)

[√] VS Code (version 1.29.1)
    • VS Code at C:\Users\xxx\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 2.21.0

[√] VS Code, 64-bit edition (version 1.26.0)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 2.21.0

[√] Connected device (1 available)
    • Pixel 3 • xxx • android-arm64 • Android 9 (API 28)

• No issues found!

Thanks for the report. Can you help me understand the issue better?

Here's what I think happened. Is this correct:

  • launch Android Studio
  • create a Flutter project using no http proxy
  • creation does not succeed, repeats "packages get"
  • close and restart Android Studio
  • notice the editor has a banner instructing that "packages get" needs to run
  • click the banner button to get packages
  • see error output
  • diagnose a proxy issue
  • set the correct proxy and test that a connection to pub does work
  • problem resolved (with some difficulty)

Hi

Nearly correct.
At point "set correct proxy and test that a connection to pub does work". I went to the proxy settings to verify that my proxy settings are correct. "Automatic proxy configuration URL" has a valid url. Then I press the "Check connection" button at the bottom and enter "https://pub.dartlang.org/" and get "success".
So it appears that android studio can use the proxy info and make the connection, but "packages get" doesn't get the same or no proxy information at all? Hence the "could not resolve".

Thanks for the additional info. I don't have a fix yet, but to get a work-around I want to make sure you understand the architecture. The Flutter plugin runs in the IDE and uses the IDE's proxy config (which is working). The project creation is done by the Flutter SDK, which is outside the IDE. You might need to set up a proxy for the flutter tool. Admittedly, that sounds like something the plugin should be doing but apparently it is not.

@pq for additional insights.

pq commented

@Fredro: to be clear, are you setting up your proxy info in preferences here?:

image

@pq correct

pq commented

/cc @alexander-doroshko : since this should probably get addressed in the Dart Plugin too for vanilla pub actions.

Right, currently, IDE simply starts tools from the Dart/Flutter SDK without caring about proxy configured in the IDE settings. As far as I understand, if a proxy is configured in the OS as recommended here, this will work because the IDE and therefore Flutter/Dart tools will inherit OS proxy settings.

pq commented

Thanks @alexander-doroshko! What's the recommended way to launch IDEA w/ custom environment settings?

AFAIU, IDE inherits env vars from where it is started from. I mean if you have a proxy configured globally on Windows PC then IDE will be started with these env vars. I'm not sure you need to start IDE w/ custom environment settings. I haven't tested the use case myself though.

I know that the IDE uses its proxy settings when the IDE itself needs to access the internet, I mean, verify license, fetch documentation, check for updates, etc. I'm not sure IDE needs to use its proxy settings when it launches 3rd party tools like tools from the Dart/Flutter SDK. I may be wrong, but as far as I can see, IDE doesn't use proxy settings for npm or node.js tools integration.

pq commented

Great thanks @alexander-doroshko!

@Fredro : maybe try setting https_proxy as suggested in the pub notes? Let us know if that works!

@pq Yes, setting https_proxy seems to work. As said above I also thought 3rd party tools would use IDE proxy settings since they are executed from it. But if using global env vars for setting proxy for this tool is the proper way, I'll accept it and you can close the issue. Also thanks for looking into it.

pq commented

Thanks for verifying @Fredro! I agree this isn't ideal and have turned this into a feature tracking issue. In the meantime I added a note to the known issues section of our readme w/ the work-around (#2943). Thanks again for helping us understand the issue.

Cheers!