RobbNesp RobbNesp - 6 months ago 356
Android Question

ionic failed to download gradle 2.2.1 when build android project

I started learning ionic today, I follow the official simple tutorial here, but get stuck when i tried to build my project.

I'm on network that use proxy, I already set my http and https proxy on my bashrc file (I'm using Ubuntu 16.04 LTS). Can anyone help to crack my problem?

$ ionic build android
Running command: /home/username/Dropbox/Android/ionic/myApp/hooks/after_prepare/010_add_platform_class.js /home/username/Dropbox/Android/ionic/myApp
add to body class: platform-android
ANDROID_HOME=/media/username/Data/Android/Sdk-linux
JAVA_HOME=/usr/lib/jvm/java-8-oracle
Downloading http://services.gradle.org/distributions/gradle-2.2.1-all.zip

Exception in thread "main" java.lang.RuntimeException: java.net.ConnectException: Connection timed out
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.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at java.net.Socket.connect(Socket.java:538)
at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:432)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:527)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:211)
at sun.net.www.http.HttpClient.New(HttpClient.java:308)
at sun.net.www.http.HttpClient.New(HttpClient.java:326)
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1169)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1105)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:999)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:933)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
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
Error: Error code 1 for command: /home/username/Dropbox/Android/ionic/myApp/platforms/android/gradlew with args: cdvBuildDebug,-b,/home/username/Dropbox/Android/ionic/myApp/platforms/android/build.gradle,-Dorg.gradle.daemon=true,-Pandroid.useDeprecatedNdk=true


This is details of my nodejs, npm and ionic :

$ nodejs -v
v4.4.4
$ ionic -v
1.7.14
$ npm -v
2.15.1


I tested to give append PROXY on my command, it still does't work

$ PROXY=proxy.uthm.edu.my:8080 ionic build android

Answer

I got solution for this kind of problem..

We need to export java proxy parameter and then build the project

$ export JAVA_OPTS="-Dhttp.proxyHost=proxy.uthm.edu.my -Dhttp.proxyPort=8080 -Dhttps.proxyHost=proxy.uthm.edu.my -Dhttps.proxyPort=8080"

$ ionic build android

You ionic should able to download gradle and build project for ionic apps.