首页 > 解决方案 > 尽管设置了代理明确,但在代理后面运行的颤动无法下载 gradle 依赖项

问题描述

Flutter 在获取依赖项时应该使用代理环境变量,但它没有这样做。

> $env:http_proxy="127.0.0.1:8090"
> $env:https_proxy="127.0.0.1:8090"
> $env:NO_PROXY="localhost,127.0.0.1"

> flutter create app
> cd app
> flutter run

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'android'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.5.0.
     Searched in the following locations:
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.pom
       - https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.5.0/gradle-3.5.0.jar
     Required by:
         project :

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

我知道使用 VPN 也是一种选择。但我更喜欢使用代理。操作系统:Windows 10

标签: androidflutter

解决方案


如果你在代理后面,你必须再次明确地为 gradle 设置代理,意味着gradle尊重环境变量,这有点烦人。不管怎样,你去吧。

在您的主文件夹中的目录gradle.properties下创建一个文件。.gradle

code ~/.gradle/gradle.properties

将以下内容粘贴到其中

systemProp.http.proxyHost={ProxyIP}
systemProp.http.proxyPort={ProxyPort}
systemProp.http.nonProxyHosts=*.jitpack.io, *.maven.org
systemProp.https.proxyHost={ProxyIP}
systemProp.https.proxyPort={ProxyPort}
systemProp.https.nonProxyHosts=*.jitpack.io, *.maven.org

就我而言maven.orgjitpack.io可以直接浏览域。

并且不要忘记flutter clean之前运行flutter run。看看发生了什么运行flutter run -v


推荐阅读