在 Android Studio 中设置 Http 代理
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24459182/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set up Http Proxy in Android Studio
提问by OhWhen
I have read multiple similar questions and the documentation but I have not been able to solve my issue of getting by the corporate firewall my machine sits behind. The error I am getting is 'Failed to refresh Gradle project' Unknown host services.gradle.org. Everything I have read and understand lead me to believe this is a http proxy issue. I have tried setting the proxy properties in the gradle.properties file in my Project folder so my gradle.properties file looks like :
我已经阅读了多个类似的问题和文档,但我无法解决我的机器位于公司防火墙后面的问题。我得到的错误是“无法刷新 Gradle 项目”未知主机 services.gradle.org。我所阅读和理解的一切让我相信这是一个 http 代理问题。我尝试在我的项目文件夹中的 gradle.properties 文件中设置代理属性,因此我的 gradle.properties 文件如下所示:
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Settings specified in this file will override any Gradle settings
# configured through the IDE.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError - Dfile.encoding=UTF-8
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
systemProp.http.proxyHost=proxy.company.com
systemProp.http.proxyPort=83
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password
systemProp.http.auth.ntlm.domain=domain
systemProp.https.proxyHost=proxy.company.com
systemProp.https.proxyPort=83
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password
systemProp.https.auth.ntlm.domain=domain
I have also tried setting the Global Gradle Settings by going File->Settings->Gradle and setting the Gradle VM Options using:
我还尝试通过转到 File->Settings->Gradle 并使用以下方法设置 Gradle VM 选项来设置全局 Gradle 设置:
-Dhttp.proxyHost=proxy.company.com -Dhttp.proxyPort=83 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password
I cannot see any documentation of where else to set this http proxy setting, please help if you can.
我看不到任何其他地方设置此 http 代理设置的文档,如果可以,请提供帮助。
回答by MarkosyanArtur
try to add domain into gradle global settings
尝试将域添加到 gradle 全局设置中
-Dhttp.proxyHost=proxy.company.com -Dhttp.proxyPort=83 -Dhttp.proxyUser=username -Dhttp.proxyPassword=password -Dhttp.auth.ntlm.domain=domain
It helps for me.
它对我有帮助。
回答by samutopia
Had a similar issue getting android studio to open up behind a corporate firewall. It would crash after looking for SDK updates and failing. I used a freeware called "proxycap" and input the proxy settings for the corporation (available in the my computer's internet settings). Now it works fine! There are other proxy freewares (proxify...), but I chose this is one of the programs with a program level proxy settings, where I could set up the proxy for android studio only.
有一个类似的问题让 android studio 在公司防火墙后面开放。它会在寻找 SDK 更新并失败后崩溃。我使用了一个名为“proxycap”的免费软件,并输入了公司的代理设置(在我电脑的互联网设置中可用)。现在它工作正常!还有其他代理免费软件(proxify ...),但我选择这是具有程序级代理设置的程序之一,我只能在其中为 android studio 设置代理。
回答by Shaji Thorn Blue
I dont know if there was proxy option in previous version, but in v1.0.1 and above you can find it in File-> Settings -> IDE settings.
我不知道之前版本有没有代理选项,但在 v1.0.1 及以上版本你可以在文件-> 设置 -> IDE 设置中找到它。
回答by Viswa
//gradle.properties
systemProp.http.proxyHost=www.somehost.org
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost