为 Android Studio 或者 Android 项目设置代理

栏目: IOS · Android · 发布时间: 6年前

内容简介:本文记录给 Android Studio 设置代理,并添加白名单。适用于 Jenkins 等 CI/CD 环境。有修改配置文件和命令行2种方式。前置环境:一个 HTTP 代理需要加入白名单的域名:*.nonproxydomains.com

本文记录给 Android Studio 设置代理,并添加白名单。适用于 Jenkins 等 CI/CD 环境。有修改配置文件和命令行2种方式。

前置环境:一个 HTTP 代理

  • Host:xx.xx.xx.xx
  • Port:xxxx
  • User:userid
  • Password:password

需要加入白名单的域名:*.nonproxydomains.com

配置

有2种使用方式:

gradle.properties

方式一:修改 gradle.properties

如果只想修改当前项目,则修改对象是当前项目下的 gradle.properties 文件

如果想修改后对所有使用 gradle 构建的项目都起作用,则修改当前用户下 .gradle/gradle.properties 文件。对于 类Unix系统(Linux、macOs) 是 ~/.gradle/ 目录(GRADLE_USER_HOME),Windows 是 系统盘下的 /User/XXX/.gradle/ 目录。

要添加的内容如下:

systemProp.http.proxyHost=xx.xx.xx.xx
systemProp.http.proxyPort=xxxx
systemProp.http.proxyUser=userid
systemProp.http.proxyPassword=password
systemProp.http.nonProxyHosts=*.nonproxydomains.com|localhost

systemProp.https.proxyHost=xx.xx.xx.xx
systemProp.https.proxyPort=xxxx
systemProp.https.proxyUser=userid
systemProp.https.proxyPassword=password
systemProp.https.nonProxyHosts=*.nonproxydomains.com|localhost

方式二:命令行方式

首先看个 Android 打包的完整命令,然后根据平台差异做一下说明(以macOS下为例):

cd projectRoot
./gradlew :app:assembleDebug -Dhttp.proxyHost=xx.xx.xx.xx -Dhttp.proxyPort=xxxx -Dhttp.nonProxyHosts=*.nonproxydomains.com|localhost -Dhttp.proxyUser=userid -Dhttp.proxyPassword=password -Dhttps.proxyHost=xx.xx.xx.xx -Dhttps.proxyPort=xxxx -Dhttps.nonProxyHosts=*.nonproxydomains.com|localhost -Dhttps.proxyUser=userid -Dhttps.proxyPassword=password
## 换行看下参数,和配置文件的参数对应
# -Dhttp.proxyHost=xx.xx.xx.xx 
# -Dhttp.proxyPort=xxxx 
# -Dhttp.nonProxyHosts=*.nonproxydomains.com|localhost 
# -Dhttp.proxyUser=userid 
# -Dhttp.proxyPassword=password

# -Dhttps.proxyHost=xx.xx.xx.xx 
# -Dhttps.proxyPort=xxxx 
# -Dhttps.nonProxyHosts=*.nonproxydomains.com|localhost 
# -Dhttps.proxyUser=userid 
# -Dhttps.proxyPassword=password

这里特别说下 http.nonProxyHosts=*.nonproxydomains.com|localhost 中的 | 符号,命令行使用时可能因为平台差异、字符转义问题需要特殊处理。

当然,如果按照上面的方式没有问题,则不需要特殊处理。

对于 Unix/Linux 系统:管道字符 | 可能需要反斜杠 \ 来转义,使它不被解释为 shell 管道。

-Dhttp.nonProxyHosts=*.nonproxydomains.com|localhost
# 当上面的使用方式有问题时改为:
-Dhttp.nonProxyHosts=*.nonproxydomains.com\|localhost

对于 Windows 系统: | 可能需要反斜杠 ^ 来转。

-Dhttp.nonProxyHosts=*.nonproxydomains.com|localhost
# 当上面的使用方式有问题时改为:
-Dhttp.nonProxyHosts=*.nonproxydomains.com^|localhost

对于使用字符串(双引号包裹)时,也需要转义处理

-Dhttp.nonProxyHosts=*.nonproxydomains|localhost
# 作为字符串处理时
-Dhttp.nonProxyHosts="*.nonproxydomains\|localhost"

如果有什么问题或者意见,可以通过下面的方式和我联系


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

生态战略:设计未来企业新模式

生态战略:设计未来企业新模式

周文艺 / 机械工业出版社 / 2017-3 / 49.00

思想影响战略,战略决定组织。在充满高度不确定性的今天,企业要生存和发展,必须不断进行组织变革与进化,跨越不连续性的鸿沟。本书分析了大量互联网生态型企业的案例,从生态思维进化、生态战略构建和生态组织变革三个角度出发,全面阐述了企业的进化之路。 本书认为,生态是企业进化的核心思想,企业须重新定义增长模式,从封闭的企业链转向开放的价值网,不断创新文化、技术和连接,培育新物种,实现企业从技术生态位到......一起来看看 《生态战略:设计未来企业新模式》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

在线进制转换器
在线进制转换器

各进制数互转换器

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具