Proxy Error when downloading gradle zip during "ionic emulate android"

I’m working with my first app and after getting my system setup (except for this, I guess), I get the following error when I try to launch the app in the android emulator. I’m on Windows 7, on a corporate network, behind a proxy server.

D:\dev\<company>\<project>\App>ionic emulate android
Running command: "D:\Program Files\nodejs\node.exe" D:\dev\<company>\<project>\App\hooks\after_prepare\010_add_platform_class.js D:\dev\<company>\<project>\App
add to body class: platform-android
Running command: cmd "/s /c "D:\dev\<company>\<project>\App\platforms\android\cordova\run.bat --emulator""
ANDROID_HOME=C:\Users\<user>\AppData\Local\Android\android-sdk
JAVA_HOME=C:\Program Files\Java\jdk1.6.0_38
WARNING : no emulator specified, defaulting to x86-5.5.1
Waiting for emulator...
emulator: device fd:872

HAXM is working and emulator runs in fast virt mode
creating window 0 0 578 1026
emulator: emulator window was out of view and was recentered

Booting up emulator (this may take a while).......BOOT COMPLETE
Running: D:\dev\<company>\<project>\App\platforms\android\gradlew cdvBuildDebug -b D:\dev\<company>\<project>\App\platforms\android\build.gradle -PcdvBuildArch=x86 -Dorg.grad
le.daemon=true
Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip

Exception in thread "main" java.lang.RuntimeException: java.io.IOException: Server returned HTTP response code: 401 for URL: http://services.gradle.org/distribu
tions/gradle-2.2.1-all.zip
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:78)
        at org.gradle.wrapper.Install.createDist(Install.java:47)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:129)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:48)
Caused by: java.io.IOException: Server returned HTTP response code: 401 for URL: http://services.gradle.org/distributions/gradle-2.2.1-all.zip
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1459)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:59)
        at org.gradle.wrapper.Download.download(Download.java:45)
        at org.gradle.wrapper.Install$1.call(Install.java:60)
        at org.gradle.wrapper.Install$1.call(Install.java:47)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
        ... 3 more

D:\dev\<company>\<project>\App\platforms\android\cordova\node_modules\q\q.js:126
                    throw e;
                          ^
Error code 1 for command: cmd with args: /s /c "D:\dev\<company>\<project>\App\platforms\android\gradlew cdvBuildDebug -b D:\dev\<company>\<project>\App\platforms\android\build.gradle -PcdvBuildArch=x86 -Dorg.gradle.daemon=true"
Error: cmd: Command failed with exit code 1
    at ChildProcess.whenDone (C:\Users\<user>\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\cordova\superspawn.js:139:23)
    at ChildProcess.emit (events.js:110:17)
    at maybeClose (child_process.js:1015:16)
    at Process.ChildProcess._handle.onexit (child_process.js:1087:5)
^CTerminate batch job (Y/N)? y

Base don the 401, I assume that Java isn’t getting through our proxy. If that’s the case, is there any way for me to set credentials for this call? I can enter that path in Chrome and download the zip file with no problem so the 401 seems to be on my end and not at services.gradle.org.

find ‘gradle.properties’ file in ‘.gradle’ folder and add your proxy detail like below then try again. it will solve problem

systemProp.http.proxyHost=your_proxy_host
systemProp.http.proxyPort=your_proxy_port
systemProp.https.proxyHost=your_proxy_host
systemProp.https.proxyPort=your_proxy_port

2 Likes

Thanks! I like this suggestion better than what I ended up doing.

To solve the problem immediately I followed an answer I found on StackOverflow that suggested downloading the file, saving it to the platforms\android path and then updating build.js to point to this path instead of downloading the file from services.gradle.org. Your solution fixes the root cause, +1!

Thanks,
Mike Devenney

This is because of gradle error Download the file
http://services.gradle.org/distributions/gradle-2.14.1-all.zip
and extract it in any of directory and set the path by open cmd and enter
setx path (extracted direstory)/bin
after reopen cmd and check whether the gradle is works or not by give
gradle -v
it shows the gradle version output .
Now the error is fixed run
ionic build android

I’m facing the same problem when running “ionic cordova build anroid” command.
Solutions I’ve tried:

  1. Setting http_proxy and https_proxy environment variables.
  2. I could not find gradle.properties anywhere in my project so created one at the base path of the project with the following entries:
    systemProp.http.proxyHost=my_proxy_host (without http)
    systemProp.http.proxyPort=my_proxy_port
    systemProp.https.proxyHost=my_proxy_host (without http/https)
    systemProp.https.proxyPort=my_proxy_port
  3. I’ve downloaded the gradle-3.3-all.zip (this was the version in my GradleBuilder.js) and placed it in my project and modified GradleBuilder.js accordingly. It fixes this but the command tries to download some *.pom files where it times out.
    Can someone suggest me anything that I can try beyond this.
    P.S: All the above things are working on VM. So I kinda believe it is an issue due to the proxy

Thanks in advance!

is there any one found the solution ?? i am also facing the same issue