Android-runtime: Problem with Gradle

Created on 11 Apr 2016  Â·  15Comments  Â·  Source: NativeScript/android-runtime

_From @munseym on April 5, 2016 23:16_

tns doctor recognizes my gradle installation:
log2.txt

However, when I run tns run android or tns emulate android, it tries to download gradle, and fails on the proxy setting. Proxy is correctly set in config.json, but this piece does not seem to honor that setting. Proxy is also set in the Java installation and http_proxy environment variable.

C:\Users\xxxx\Documents\angular\sample-ng-todomvc>tns run android
Executing before-prepare hook from C:\Users\xxxx\Documents\angular\sample-ng-todomvc\hooks\before-prepare\nativescript-dev-typescript.js
Found peer TypeScript 1.8.9
Project successfully prepared
Downloading https://services.gradle.org/distributions/gradle-2.8-bin.zip

Exception in thread "main" java.net.UnknownHostException: services.gradle.org
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:173)
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.protocol.https.HttpsClient.(HttpsClient.java:264)
at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:367)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
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.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1513)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at org.gradle.wrapper.Download.downloadInternal(Download.java:58)
at org.gradle.wrapper.Download.download(Download.java:44)
at org.gradle.wrapper.Install$1.call(Install.java:59)
at org.gradle.wrapper.Install$1.call(Install.java:46)
at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
at org.gradle.wrapper.Install.createDist(Install.java:46)
at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:126)
at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
Command C:\Users\xxxx\Documents\angular\sample-ng-todomvc\platforms\android\gradlew.bat failed with exit code 1

_Copied from original issue: NativeScript/NativeScript#1897_

low bug

All 15 comments

_From @xuezier on April 6, 2016 7:43_

set the http proxy to the download.
In Console window. enter the code:
set http_proxy=http://127.0.0.1:your_proxy_port
set https_proxy=http://127.0.0.1:your_proxy_prot
then:
tns run android
Should be able to solve the problem.

_From @NickIliev on April 6, 2016 11:17_

@munseym
Can you verify @xuezier solution?

Also you can check the following steps as described here

  • On your file system, locate the directory where the nativescript npm package is installed.
  • In a text editor, open config → config.json.
  • Set USE_PROXY to true.
  • Set PROXY_PORT.
  • Set PROXY_HOSTNAME.
  • Make sure to preserve the quotation marks and commas as in the initial config.json file.

Alternativly you can check this discussion #302

Hi @munseym,
Did you try what @NickIliev suggested? If you're trying to use a proxy, this might help.

Same issue here - none of the proposed solutions above seem to work.

Fixed it by adding the following line inside the gradlew.bat file:

set DEFAULT_JVM_OPTS="-Dhttps.proxyHost=HOST -Dhttps.proxyPort=PORT -Dhttps.proxyUser=USER -Dhttps.proxyPassword=PASSWORD -Dhttp.proxyHost=HOST -Dhttp.proxyPort=PORT -Dhttp.proxyUser=USER -Dhttp.proxyPassword=PASSPWORD"

Please note that the HOST property doesn't take the http:// prefix.

Hi @ghpabs,
Thank you for sharing this workaround.
Because gradlew.bat, shouldn't be changed because it's created by the wrapp command and it can be easily overridden, it's better to set the properties you described in the gradle.properties. You can read about more about gradle.properties file here

Hello @enchev
I tried to "locate the directory where the nativescript npm package is installed" and I don't find where in filesystem is. Where should it be?

@Kurara if you have the same gradle problem with proxies use @ghpabs workaround.

Thank you. I tried also adding that line to gradlew.bat and It doesn't fix it. I hate these proxys and all the problems they make always. Sorry for necromancing post u.u The problem says:

Downloading https://services.gradle.org/distributions/gradle-2.8-bin.zip

Exception in thread "main" java.net.ConnectException: Connection timed out: connect

@Kurara you shouldn't change the gradle.bat file as it easily is overridden. You need to make the proxy configuration in the gradle.properties file located in <app_name>/platforms/android/gradle.properties: see more here

@Plamen5kov thank you very much but it seems I'm not able to make it run. Should I open a new post with my problem or paste it here? I dont have gradle.properties but I found android\gradlewrapper\gradle-wrapper.properties

@Kurara if your problem is the same as described here, you must create gradle.properties as described in the link I send you. If your problem is with the gradle proxies feel free to reopen this issue.

_Edit:_

  • go to /platforms/android/
  • create gradle.properties file
  • paste this content and fill in the HOST, PORT, USER and PASSWORD fields

I fixed it! I forgot to wirte https proxy. I create gradle.properties and modified both it and gradle-wrapper.properties

there's no way to download hte gradle of zip and install it manuelly ?

@Fabiyo-90 the proposed solutions in http://stackoverflow.com/questions/22896569/how-to-use-gradle-zip-in-local-system-without-downloading-when-using-gradle-wrap are all valid. Feel free to experiment. Mind you, when uninstalling/deleting the platforms directory you will delete the gradle wrapper properties file, so you need to work out a way to make the changes persistent.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NathanaelA picture NathanaelA  Â·  3Comments

Plamen5kov picture Plamen5kov  Â·  5Comments

triniwiz picture triniwiz  Â·  4Comments

georgeedwards picture georgeedwards  Â·  3Comments

Plamen5kov picture Plamen5kov  Â·  4Comments