新建React Native项目,执行 'react-native run-android' 报错!



  • 系统:Windows7 64位;
    开发工具: Webstorm 2017.1;
    Android 模拟器: Genymotion;

    新建React Native项目,没有加入任何个人代码,直接执行 'react-native run-android' 报错!错误内容具体如下:

    Scanning 574 folders for symlinks in E:\ReactNative Workspace\myReactProject\node_modules (14ms)
    Starting JS server...
    Building and installing the app on the device (cd android && gradlew.bat installDebug)...
    Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip

    Exception in thread "main" java.net.UnknownHostException: services.gradle.org
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:178)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:157)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)
    at java.net.Socket.connect(Socket.java:579)
    at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:618)
    at sun.security.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:160)
    at sun.net.NetworkClient.doConnect(NetworkClient.java:180)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:378)
    at sun.net.www.http.HttpClient.openServer(HttpClient.java:473)
    at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:270)
    at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:327)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:191)
    at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:931)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:177)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1299)
    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, read the error above for details.
    Make sure you have an Android emulator running or a device connected and have
    set up your Android development environment:
    https://facebook.github.io/react-native/docs/android-setup.html0_1505814143931_QQ截图20170919174206.png

    网上找了一大圈文章,主要说SDK安装有问题。
    检查了一下,SDK安装正常,命令行中 ‘'adb version' 可以看到版本号,
    0_1505813907002_QQ截图20170919173539.png
    环境变量也配置正确,
    0_1505814025149_QQ截图20170919173941.png 0_1505814038443_QQ截图20170919173959.png

    Android模拟器也启动着,
    0_1505814092891_QQ截图20170919174120.png

    但就是一直报错,请大神指教,带带新人!!


  • administrators

    Downloading https://services.gradle.org/distributions/gradle-2.14.1-all.zip

    Exception in thread "main" java.net.UnknownHostException: services.gradle.org

    gradle下载被墙,后面都是瞎折腾



  • 谢谢晴明老师指点,前面的问题解决了。用浏览器直接访问 https://services.gradle.org/distributions/gradle-2.14.1-all.zip 下载ZIP包,放入本地 0_1505979390040_QQ截图20170921153613.png目录下,解决前面的报错问题。
    但又出现新问题,命令行报错如下:0_1505979451961_QQ截图20170921153701.png

    在网上找了相关问题,说是gradle版本问题,将项目目录 android/build.gradle 中的版本号(我的项目中的是‘ gradle:2.2.3 ’)替换为 android/gradle.properties 中的版本号(我的项目中的是 ‘gradle-2.14.1’)0_1505979554110_QQ截图20170921153841.png 0_1505979617280_QQ截图20170921153901.png

    ==============================================================================================================

    0_1505979669202_QQ截图20170921154044.png0_1505979692082_QQ截图20170921154058.png

    按照上面的方法依旧报错,如下:
    0_1505980171663_啊飒飒.png

    请问,这个是什么原因。无法获取网上gradle资源,还是被墙了么?


  • administrators

    对的,不翻墙寸步难行



  • @晴明 感谢老师指点,十分感谢!


登录后回复