首页 > 解决方案 > 本地运行 react native 应用失败

问题描述

使用react-native init FirstApp我创建了一个示例项目,当我尝试使用我运行应用程序react-native run-android时出现以下错误:

FAILURE:构建失败并出现异常。

A problem occurred configuring root project 'MyFirstApp'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not download builder.jar (com.android.tools.build:builder:3.4.1)
      > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.4.1/builder-3.4.1.jar'.
         > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/builder/3.4.1/builder-3.4.1.jar'.
            > Connect to dl.google.com:443 [dl.google.com/172.217.212.91, dl.google.com/172.217.212.190, dl.google.com/172.217.212.93, dl.google.com/172.217.212.136] failed: Connection timed out: connect
   > Could not download manifest-merger.jar (com.android.tools.build:manifest-merger:26.4.1)
      > Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/26.4.1/manifest-merger-26.4.1.jar'.
         > Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/manifest-merger/26.4.1/manifest-merger-26.4.1.jar'.
            > Connect to dl.google.com:443 [dl.google.com/74.125.124.190, dl.google.com/74.125.124.93, dl.google.com/74.125.124.136, dl.google.com/74.125.124.91] failed: Connection timed out: connect```

Can somebody help me out here?

标签: react-nativereact-native-android

解决方案


我通过设置代理配置得到了解决方案。gradle.properties在文件中设置以下配置


# HTTP proxy configuration
systemProp.http.proxyHost=your.proxy.host
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=password

# HTTPS proxy configuration
systemProp.https.proxyHost=your.proxy.host
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=username
systemProp.https.proxyPassword=password

推荐阅读