Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Gradle build and proxy settings

Discussion in 'Editor & General Support' started by caletbak2, Mar 21, 2017.

  1. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    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 !!
     
    Last edited: Mar 22, 2017
  2. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    I have updated with the error log.

    Any idea about this?
     
  3. Wim-Wouters

    Wim-Wouters

    Joined:
    Sep 26, 2012
    Posts:
    34
    Did you find a fix?
     
  4. caletbak2

    caletbak2

    Joined:
    Oct 15, 2014
    Posts:
    13
    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
     
    Wim-Wouters likes this.
  5. Wim-Wouters

    Wim-Wouters

    Joined:
    Sep 26, 2012
    Posts:
    34
    OK, I just seemed to have an older version of JDK still installed next to the new one... uninstallled it... FIXED
     
  6. zhao5359228

    zhao5359228

    Joined:
    Feb 28, 2017
    Posts:
    3
    Thx, you saved me.
     
  7. hugo-yu

    hugo-yu

    Joined:
    Nov 20, 2013
    Posts:
    5
    set "gradle.properties" content to:

    #http proxy setup
    systemProp.http.proxyHost=<your proxy host>
    systemProp.http.proxyPort=<your proxy port>

    #https proxy setup
    systemProp.https.proxyHost=<your proxy host>
    systemProp.https.proxyPort=<your proxy port>

    fix my problem ~
     
    socialtrens likes this.
  8. socialtrens

    socialtrens

    Joined:
    Oct 23, 2017
    Posts:
    46
    Thanks! This fix it!

    Here I make a full tutorial:

    Copy & paste:

    Code (csharp):
    1. systemProp.http.proxyHost=127.0.0.1 // example ip proxy, change with your ip proxy, dont use http
    2. systemProp.http.proxyPort=8080 // example port proxy, change with your port proxy
    3. systemProp.https.proxyHost=127.0.0.1 // example ip proxy, change with your ip proxy, dont use https
    4. 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.
     
    Last edited: Jan 19, 2023