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

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

内容简介:本文记录给 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-5-8 / 59.00

近5年来网络信息量增长了近10倍,信息极度过剩。移动互联网以碎片化、强黏度以及惊人的覆盖率给传统的商业环境带来了巨大的影响,向陈旧的广告、公关、媒体行业展开了深度的冲击。 传统的以渠道为中心的传播思想几近失效,优秀内容成为了各行业最稀缺的资产,这是时代赋予内容生产者的巨大机会。本书作者在多年经验和大量案例研究的基础上,总结出了移动互联网时代的内容运营方法论——共鸣,它将告诉我们如何收获核心粉......一起来看看 《共鸣:内容运营方法论》 这本书的介绍吧!

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

在线压缩/解压 JS 代码

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换