Skip to content

[Android] Connection refused from Gradle when behind a proxy #2726

Closed
@nadeemshaik

Description

@nadeemshaik

Well, I am getting this error when I am trying to run "react-native run-android". Seems to be a simple error but I can't figure it out a solution.

Can this be because of a proxy server (University restrictions) : Does react-native-cli accept proxy params ?

Just in case:

Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Downloading https://services.gradle.org/distributions/gradle-2.4-all.zip

Exception in thread "main" java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:345)
    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 sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:649)
    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.<init>(HttpsClient.java:275)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:371)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1103)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:997)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1511)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1439)
    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)
Could not install the app on the device, see the error above.

Activity

mkonicek

mkonicek commented on Sep 15, 2015

@mkonicek
Contributor

Might be related to the proxy indeed.

Building and installing the app on the device (cd android && ./gradlew installDebug)...
Downloading https://services.gradle.org/distributions/gradle-2.4-all.zip

Can you fetch it using your browser as well as wget?

mkonicek

mkonicek commented on Sep 15, 2015

@mkonicek
Contributor

The CLI doesn't accept proxy params.

changed the title [-]Exception in thread "main" java.net.ConnectException: Connection refused[/-] [+][Android] Connection refused from Gradle when being a proxy[/+] on Sep 15, 2015
changed the title [-][Android] Connection refused from Gradle when being a proxy[/-] [+][Android] Connection refused from Gradle when behind a proxy[/+] on Sep 15, 2015
nadeemshaik

nadeemshaik commented on Sep 15, 2015

@nadeemshaik
Author

Hey @mkonicek , I tried that, but gives the exact same error. After googling a bit more about gradle settings, just found out the solution though.I just set the following in gradle.properties in the android folder

systemProp.http.proxyHost=proxyHost
systemProp.http.proxyPort=proxyPort

systemProp.https.proxyHost=proxyHost
systemProp.https.proxyPort=proxyPort

Works now :)

kmagiera

kmagiera commented on Sep 15, 2015

@kmagiera
Contributor

great to hear you've found the solution

dharmesh-khandelwal

dharmesh-khandelwal commented on Oct 6, 2016

@dharmesh-khandelwal

@nadeemshaik Thanks, I had the same issue. Fixed by setting proxy in gradle properties.

s0nskar

s0nskar commented on Nov 21, 2016

@s0nskar

If your proxy uses authentication add these line too

systemProp.http.proxyUser=YOUR_USERNAME
systemProp.http.proxyPassword=YOUR_PASSWORD
tassoman

tassoman commented on Jan 13, 2017

@tassoman

must be set in android/gradle.proprieties not in settings.gradle

adrianovieira

adrianovieira commented on Jan 30, 2017

@adrianovieira

Can I do these proxy settings as a global settings or only by project as <AwesomeProject>/android/gradle.proprieties?

husainkhan

husainkhan commented on Sep 6, 2017

@husainkhan

Still not Working.
I did set the proxy and the port but still it gives the same error.

botdotcom

botdotcom commented on Mar 8, 2018

@botdotcom

Not working for me either!

sujitpk-perennial

sujitpk-perennial commented on Mar 13, 2018

@sujitpk-perennial

No luck for me. I am facing this problem for all projects now.

bpatel444

bpatel444 commented on Apr 12, 2018

@bpatel444

You can set the proxy to automatic and rerun the android studio and it worked for me.

Thank you!!

locked as resolved and limited conversation to collaborators on Jul 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @tassoman@mkonicek@kmagiera@nadeemshaik@adrianovieira

        Issue actions

          [Android] Connection refused from Gradle when behind a proxy · Issue #2726 · facebook/react-native