Flutter app behind corporate firewall throws TLS e

2020-03-04 02:45发布

问题:

Recently have installed Flutter and exploring hello-world app. Followed all steps mentioned at https://flutter.io/get-started/ and was able to run

:: flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel beta, v0.5.1, on Microsoft Windows [Version 10.0.15063], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[√] Android Studio (version 3.1)
[!] VS Code, 64-bit edition (version 1.26.0)
[√] Connected devices (1 available)
! Doctor found issues in 1 categories.

Also was able to create app skeleton with following command;

:: flutter create myapp

But when it was trying to install all dependencies mentioned under pubspec.yaml, it started showing error and kept trying to reconnect again. Here is the logs,

Running "flutter packages get" in hello_world...
Got TLS error trying to find package cupertino_icons at https://pub.dartlang.org.
pub get failed (69) -- attempting retry 1 in 1 second...
Got TLS error trying to find package cupertino_icons at https://pub.dartlang.org.
pub get failed (69) -- attempting retry 2 in 2 seconds...

I suspect its because of firewall and for other package managers I have been using proxy server to enable fetch which works just fine. I could not find a way to implement such proxy for flutter or pub. I also tried to use china server but that also didn't helped me. I have installed and uninstalled couple of time to make sure cache is not causing this issue.

Does anyone have figured this out yet?

回答1:

I had the same issue. I am working in a company and I had to use https_proxy env variable to get connection.

Open cmd on Windows

set https_proxy=USERNAME:PASSWORD@hostname:port

flutter create

flutter run

flutter packages get

This worked for me, hope it helps!



回答2:

I was successful after setting the following windows environment variable.

Variable name: DART_VM_OPTIONS Variable value: --root-certs-file=path_to_cert

Where path_to_cert is the fully qualified path.



回答3:

You might need to setup a self-signed certificate to make it work correctly by setting the following enviroment variables:

On Linux:

export DART_VM_OPTIONS="--root-certs-file={path.to.certificate.file}"

On Windows:

set https_proxy="--root-certs-file={path.to.certificate.file}"