React Native填坑系列之一(Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'. > Connect to 127.0.0.1:1089 [/127.0.0.1] failed: Connection refused (Connection refused))

  1. 为什么开始React Native开发
  2. 第一个bug
  3. 转机
  4. 结语

为什么开始React Native开发

和朋友一起准备给网站配套做一款android app。经过宋小菜的scott老师在他文章中对宋小菜架构的介绍,其中提到了对React Native的使用,让我重拾信心,再加上之前有过相关经验,于是决定使用它来进行app的开发。

第一个bug

当我装好android studio并把项目初始化好了以后,我自信满满的运行react-native run-android,扎心的错误铺面而来

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'idea_app'.
> Could not resolve all artifacts for configuration ':classpath'.
> Could not resolve com.android.tools.build:gradle:3.2.1.
Required by:
project :
> Could not resolve com.android.tools.build:gradle:3.2.1.
> Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Connect to 127.0.0.1:1089 [/127.0.0.1] failed: Connection refused (Connection refused)
> Could not resolve com.android.tools.build:gradle:3.2.1.
> Could not get resource 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
> Connect to 127.0.0.1:1089 [/127.0.0.1] failed: Connection refused (Connection refused)

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
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/getting-started.html

Command failed: ./gradlew installDebug

Error: Command failed: ./gradlew installDebug
at checkExecSyncError (child_process.js:616:11)
at Object.execFileSync (child_process.js:634:13)
at runOnAllDevices (/Users/kiralin/lixiang/idea_app/node_modules/react-native/local-cli/runAndroid/runAndroid.js:299:19)
at buildAndRun (/Users/kiralin/lixiang/idea_app/node_modules/react-native/local-cli/runAndroid/runAndroid.js:135:12)
at isPackagerRunning.then.result (/Users/kiralin/lixiang/idea_app/node_modules/react-native/local-cli/runAndroid/runAndroid.js:65:12)
at process._tickCallback (internal/process/next_tick.js:68:7)

注明一下,我使用的RN版本是0.58.6是58系列最后一个版本。于是想到的第一件事情就是谷歌。最早我搜索的是Could not resolve com.android.tools.build:gradle:3.2.1.,结果发现谷歌到的第一个就是在build.gradle中加入google()方法,然而当我打开我的build.gradle文件,我发现RN官方已经加入了该方法,我顿时感到很诧异,这一招怕是行不通了。其他回答里面还有加入maven配置的,基本上也都行不通。

转机

通过仔细观察报错的栈,发现最底层的才是核心的错误,于是我搜索127.0.01:1089相关的RN回答,于是找到了一个方法,那就是将RN里的android文件夹在android studio里面打开,让android studio来帮你把依赖安好,我一看内心就觉得靠谱。

But,在AS中connection refused。于是我分析是代理的问题,恰巧吃饭了,询问了一下同事代理方面的问题,提到了端口占用,我回来检测了一下,并没有该情况,不过还好,我基本也有把握,因为这种问题应该是安卓常见问题, 接着谷歌,AS中connection refused,果然第二个答案就solve了我的problem。

下面贴一下链接解决studio Connection refused (Connection refused)

解决这个问题后,于是我react-native run-android,成功build,然后在avd中出现欢迎界面。

结语

这是RN填坑第一弹,后期有坑会继续填满


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 jaytp@qq.com

×

喜欢就点赞,疼爱就打赏