Gradle build and proxy settings

Hi all,

I am trying to build with the new Gradle system and it works, but in our company there is a network proxy and Gradle fails to build the project with a timeout exception when trying to reach and dowload some files:

stderr[

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring root project ‘gradleOut’.

Could not resolve all dependencies for configuration ‘:classpath’.
Could not resolve com.android.tools.build:gradle:2.1.0.
Required by:
:gradleOut:unspecified
Could not resolve com.android.tools.build:gradle:2.1.0.
Could not get resource ‘https://jcenter.bintray.com/com/android/tools/build/gradle/2.1.0/gradle-2.1.0.pom’.
Could not GET ‘https://jcenter.bintray.com/com/android/tools/build/gradle/2.1.0/gradle-2.1.0.pom’.
Connect to jcenter.bintray.com:443 [jcenter.bintray.com/159.122.18.156] failed: Connection timed out: connect

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
    ]

Is there any way to specify the proxy in the whole Unity Editor environment, or add some kind of Gradle settings file in the Android plugins folder, or maybe possible add some pre build script, in order to specify the proxy host and port?

Thanks !!

I have updated with the error log.

Any idea about this?

Did you find a fix?

Hi,

yes. But you need to modify or create the file “gradle.properties” inside your user folder “.gradle”.

So if you are in mac, you can find it in:

“/Users/user/.gradle”.

You can use this code in every platform to get the folder:

#if UNITY_EDITOR_WIN
strGradleFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + “\…\.gradle”;
#elif UNITY_EDITOR_OSX
strGradleFolder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments) + “/.gradle”;
#endif

Then you need to create or modify the file “gradle.properties” with this:

#http proxy setup
systemProp.http.proxyHost=url
systemProp.http.proxyPort=port
systemProp.http.nonProxyHosts=*.nonproxyrepos.com|localhost

#https proxy setup
systemProp.https.proxyHost=url
systemProp.https.proxyPort=port
systemProp.https.nonProxyHosts=*.nonproxyrepos.com|localhost

I automatically modify this file by getting the system proxy natively.

Cheers,
Calet

1 Like

OK, I just seemed to have an older version of JDK still installed next to the new one… uninstallled it… FIXED

Thx, you saved me.

set “gradle.properties” content to:

#http proxy setup
systemProp.http.proxyHost=
systemProp.http.proxyPort=

#https proxy setup
systemProp.https.proxyHost=
systemProp.https.proxyPort=

fix my problem ~

1 Like

Thanks! This fix it!

Here I make a full tutorial:

Copy & paste:

systemProp.http.proxyHost=127.0.0.1 // example ip proxy, change with your ip proxy, dont use http
systemProp.http.proxyPort=8080 // example port proxy, change with your port proxy
systemProp.https.proxyHost=127.0.0.1 // example ip proxy, change with your ip proxy, dont use https
systemProp.https.proxyPort=8080 // example port proxy, change with your port proxy

to gradle global config = current user’s gradle.properties

If you didn’t have file gradle.properties, make a new file.

  • Linux/Mac/Unices: $HOME/.gradle/gradle.properties

  • eg: /Users/limao/.gradle/gradle.properties

  • Windows: %userprofile%.gradle\gradle.properties

That’s all.