【问题标题】:react-native run-android => Could not resolve all dependencies for configuration ':classpath'react-native run-android => 无法解析配置 ':classpath' 的所有依赖项
【发布时间】:2018-08-16 16:01:44
【问题描述】:

我在环境中正确插入 java_home 并在 cmd 中测试它。我正在使用代理连接到 Internet,并且可以下载 react-native 包。 adb 设备在 cmd 上正常运行,但是在运行“react-native run-android”命令时出现以下错误:

D:\amoz\react-native\1\pro\test>react-native run-android
Scanning folders for symlinks in D:\amoz\react- 
native\1\pro\test\node_modules (8
7ms)
Starting JS server...
Building and installing the app on the device (cd android && gradlew.bat 
install
Debug)...
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by 
org.gradle.internal.reflect.JavaMethod (fi
le:/C:/Users/01/.gradle/wrapper/dists/gradle-3.5.1- 
all/42vjebfdws9pjts3l4bouoq0p
/gradle-3.5.1/lib/gradle-base-services-3.5.1.jar) to method 
java.lang.ClassLoade
r.getPackages()
WARNING: Please consider reporting this to the maintainers of 
org.gradle.interna
l.reflect.JavaMethod
WARNING: Use --illegal-access=warn to enable warnings of further illegal 
reflect
ive access operations
WARNING: All illegal access operations will be denied in a future 
release

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'test'.
> Could not resolve all dependencies for configuration ':classpath'.
 > Could not resolve com.android.tools.build:gradle:2.3.3.
 Required by:
     project :
  > Could not resolve com.android.tools.build:gradle:2.3.3.
     > Could not get resource 'https://jcenter.bintray.com/com/android/tools
/build/gradle/2.3.3/gradle-2.3.3.pom'.
        > Could not GET 'https://jcenter.bintray.com/com/android/tools/build
/gradle/2.3.3/gradle-2.3.3.pom'.
           > Connect to jcenter.bintray.com:443 [jcenter.bintray.com/108.168
.243.150] failed: Connection timed out: connect

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

BUILD FAILED

Total time: 26.739 secs
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

即使我将 Google() 添加到所有项目中的 build.gradle{} 它也无法再次工作。并且仍然给出该错误。 顺便说一句,我使用的是JDK版本9和gradle版本2.3.3

【问题讨论】:

  • 做一件事,在 Android Studio & Build 中打开你的 Android 代码,它会建议你做什么。

标签: android react-native build.gradle classpath


【解决方案1】:

很遗憾,由于美国的制裁,Jcenter 阻止了来自伊朗的请求。您可以使用 Hotspot Shield 连接到 Jcenter,其他 VPN 提供商可能无法正常工作。 我建议您通过此更改来更新您的 gradle:

1-在android/build.gradle中将gradle版本更改为classpath 'com.android.tools.build:gradle:3.1.1'

2- 将 distributionUrl 从 android/gradle/wrapper/gradle-wrapper.properties 更改为 distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

3- 像这样将存储库添加到android/build.gradle

repositories {
        mavenLocal()
        google()
        jcenter()
        maven { url "https://jitpack.io" }
        maven { url 'https://maven.google.com' }
    }

4- 启动 Hotspot Shield 并构建项目。

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-11-17
    • 2020-12-20
    • 1970-01-01
    • 1970-01-01
    • 2016-10-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多