How to fix Gradle build error when building android apk?

CommandInvokationFailure: Gradle build failed.
C:/Program Files/Java/jdk1.8.0_172\bin\java.exe -classpath “C:\Program Files\Unity(2018.3.5)\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\gradle\lib\gradle-launcher-4.6.jar” org.gradle.launcher.GradleMain “-Dorg.gradle.jvmargs=-Xmx4096m” “assembleRelease”

stderr[

FAILURE: Build failed with an exception.

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

Could not resolve all artifacts for configuration ‘:classpath’.
Could not resolve com.android.tools.build:gradle:3.2.0.
Required by:
project :
Could not resolve com.android.tools.build:gradle:3.2.0.
Could not get resource ‘https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0/gradle-3.2.0.pom’.
Could not GET ‘https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.0/gradle-3.2.0.pom’.
Connect to dl.google.com:443 [dl.google.com/127.0.1.2] failed: Connection refused: connect
Could not resolve com.android.tools.build:gradle:3.2.0.
Could not get resource ‘https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.0/gradle-3.2.0.pom’.
Could not GET ‘https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.0/gradle-3.2.0.pom’.
Connect to jcenter.bintray.com:443 [jcenter.bintray.com/127.0.1.3] failed: Connection refused: connect

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

  • Get more help at https://help.gradle.org

BUILD FAILED in 3s
]
stdout[

]

I had the same error and after two day I found the solution.
Go to C:\Users\YOURUSERNAME.gradle you should see a file named gradle.properties in this file gradle proxy can be set. for example in my case i have this configuration:

systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyPort=53556
systemProp.https.proxyHost=127.0.0.1
systemProp.http.proxyPort=53556

for more infromation about how to configure this file you can check here:
https://docs.gradle.org/current/userguide/build_environment.html

I uploaded an image of how to configure gradle.properties here:

Same issue in 2019.10f2. I posted a question but it’s still in moderation. Have you had any response on this @polham30?

Same issue.,Same issue, using 2019.10f2.l. Any solution?

Same issue in 2019.1.3. Btw, i think this is not a network issue, because when i access the link in the log in browser, the .pom file could be downloaded successfully.

Hi, everyone!
I fixed this issue.
I tried upgrade windows os.
After then gradle build error was removed.