13

When jcenter is not accessible without proxy server, to resolve dependencies, and i want to use socks instead of http proxy, how i can use it in commanad line? I know how to use http proxy:

-Dhttp.proxyHost=yourProxy -Dhttp.proxyPort=yourPort  
-Dhttp.proxyUser=usernameProxy -Dhttp.proxyPassword=yourPassoword
M.Kouchi
  • 800
  • 7
  • 12
  • 4
    You can set up proxy in **gradle.properties** configuration file. Just add this two lines to it: `systemProp.socks.proxyHost=127.0.0.1 systemProp.socks.proxyPort=1080` – Valentin Safonnikov Jan 11 '18 at 08:41
  • It worked for me after i selected `Invalidate Caches / Restart` from File menu. (Android Studio 3.5) Simple closing and reopening android studio didn't work. – Darkoob12 May 01 '20 at 08:47

4 Answers4

18

I found answer, here you can use:

./gradlew -DsocksProxyHost=yourHost 
-DsocksProxyPort=yourHostPort your-command

using above you can set socks host and port.

M.Kouchi
  • 800
  • 7
  • 12
8

Gradle only documents about how to use HTTP(s) proxy, however in the ant source code it mentions, there is enough information about how to setup the SOCKS proxy.

Add the following two lines to the gradle.properties configuration file and you are done.

systemProp.socksProxyHost=your socks proxy ip
systemProp.socksProxyPort=your socks proxy port

The format of SOCKS configuration names (socksProxyHost and socksProxyPort) differs from HTTP proxy host and port configurations (http.proxyHost and http.proxyPort).

coinfaces
  • 199
  • 2
  • 7
2

Refering to https://discuss.gradle.org/t/how-can-i-set-gradle-proxy-to-socks/15508
In the Project window change from Android to Project scope.
Then open up gradle.properties and add this line:

org.gradle.jvmargs=-DsocksProxyHost=yourHostIP -DsocksProxyPort=yourHostPort

Sync project.

user10496632
  • 463
  • 4
  • 13
0

i might be a little late but i found out that in ubuntu/Linux the proxy settings are cached in ~/.gradle/gradle.properties and I also found out that this gradle.properties is different from the one in your app inside android studio. so you need to edit the credentials in there.

do a vim ~/.gradle/gradle.properties and edit the credentials there. in my case i was using a socks proxy so i commented out all the http and https proxy hosts and ports and added one for socks. it looked like this

`systemProp.socks5ProxyHost=127.0.0.1

systemProp.socks5ProxyPort=1080`

i was able to sync gradle afterwards.

Snawar
  • 61
  • 3