react-native run-android命令抛出“ java.net.ConnectException:连接超时”错误

时间:2019-07-03 17:22:15

标签: android react-native react-native-android

我刚刚安装了Android Studio,并将所有内容都配置为given in official docs

我已经使用Chocolatey安装了Node.js。 Python27和JDK10已经安装。

我使用的是Windows 10,我的互联网连接正常(我尝试使用两个不同的WiFi连接,但没有互联网时却给出了不同的错误)

我尝试以管理员身份运行cmd,但是没有运气

C:\react_native_apps\SecondProject>react-native run-android
info Starting JS server...
info Installing the app...
Downloading https://services.gradle.org/distributions/gradle-5.4.1-all.zip

Exception in thread "main" java.net.ConnectException: Connection timed out: connect
        at java.base/java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.base/java.net.PlainSocketImpl.connect(Unknown Source)
        at java.base/java.net.Socket.connect(Unknown Source)
        at java.base/java.net.Socket.connect(Unknown Source)
        at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
        at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
        at java.base/sun.net.www.http.HttpClient$1.run(Unknown Source)
        at java.base/sun.net.www.http.HttpClient$1.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(Unknown Source)
        at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:67)
        at org.gradle.wrapper.Download.download(Download.java:52)
        at org.gradle.wrapper.Install$1.call(Install.java:62)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

error Failed to install the app. Make sure you have the Android development environment set up: https://facebook.github.io/react-native/docs/getting-started.html#android-development-environment. Run CLI with --verbose flag for more details.
Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081
Exception in thread "main" java.net.ConnectException: Connection timed out: connect
        at java.base/java.net.DualStackPlainSocketImpl.connect0(Native Method)
        at java.base/java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
        at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
        at java.base/java.net.PlainSocketImpl.connect(Unknown Source)
        at java.base/java.net.Socket.connect(Unknown Source)
        at java.base/java.net.Socket.connect(Unknown Source)
        at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
        at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
        at java.base/sun.net.www.http.HttpClient$1.run(Unknown Source)
        at java.base/sun.net.www.http.HttpClient$1.run(Unknown Source)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.base/sun.net.www.http.HttpClient.privilegedOpenServer(Unknown Source)
        at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
        at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(Unknown Source)
        at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
        at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
        at org.gradle.wrapper.Download.downloadInternal(Download.java:67)
        at org.gradle.wrapper.Download.download(Download.java:52)
        at org.gradle.wrapper.Install$1.call(Install.java:62)
        at org.gradle.wrapper.Install$1.call(Install.java:48)
        at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:69)
        at org.gradle.wrapper.Install.createDist(Install.java:48)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:107)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:63)

    at checkExecSyncError (child_process.js:616:11)
    at execFileSync (child_process.js:634:15)
    at runOnAllDevices (C:\react_native_apps\SecondProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\runOnAllDevices.js:75:39)
    at buildAndRun (C:\react_native_apps\SecondProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:137:41)
    at C:\react_native_apps\SecondProject\node_modules\@react-native-community\cli-platform-android\build\commands\runAndroid\index.js:103:12
    at processTicksAndRejections (internal/process/task_queues.js:82:5)
    at async Command.handleAction (C:\react_native_apps\SecondProject\node_modules\react-native\node_modules\@react-native-community\cli\build\cliEntry.js:166:7)

1 个答案:

答案 0 :(得分:0)

尝试手动下载该zip文件(只需将zip链接粘贴到浏览器中),然后将dl'ed zip文件放置在项目的“ android \ gradle \ wrapper”文件夹中。然后在同一文件夹中更新gradle-wrapper.properties文件。更新属性distributionURL指向您在此文件夹中复制的邮编。

因此,示例如下:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

这是对我们有用的解决方法。