【问题标题】:react-native run-android, Could not resolve all artifacts for configuration ':classpath'react-native run-android,无法解析配置“:classpath”的所有工件
【发布时间】:2019-03-06 16:17:09
【问题描述】:

我遵循React Native Getting Started 的说明,在“使用本机代码构建项目”选项卡中,适用于 Windows 和 Android。

这是 \AwesomeProject\android\build.gradle 的内容,之后我执行时出现错误:react-native run-android

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "28.0.2"
        minSdkVersion = 16
        compileSdkVersion = 28
        targetSdkVersion = 27
        supportLibVersion = "28.0.0"
    }
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}


task wrapper(type: Wrapper) {
    gradleVersion = '4.7'
    distributionUrl = distributionUrl.replace("bin", "all")
}

当我执行:react-native run-android 时,我得到以下错误输出:

D:\studio\study\reactnatv\AwesomeProject>react-native run-android
JS server already running.
Building and installing the app on the device (cd android && gradlew.bat installDebug)...

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'AwesomeProject'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.0.1.
     Searched in the following locations:
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.1/gradle-3.0.1.jar
     Required by:
         project :

* 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 3s
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.bat installDebug

Error: Command failed: gradlew.bat installDebug
    at checkExecSyncError (child_process.js:616:11)
    at Object.execFileSync (child_process.js:634:13)
    at runOnAllDevices (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:299:19)
    at buildAndRun (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:135:12)
    at isPackagerRunning.then.result (D:\studio\study\reactnatv\AwesomeProject\node_modules\react-native\local-cli\runAndroid\runAndroid.js:65:12)
    at process._tickCallback (internal/process/next_tick.js:68:7)


D:\studio\study\reactnatv\AwesomeProject>

我检查了这个US sanctions solution,但没有成功。

我做错了什么?

【问题讨论】:

    标签: android react-native build.gradle


    【解决方案1】:

    你必须在你的项目中改变这一行:

    dependencies {
    classpath 'com.android.tools.build:gradle:3.3.2'
    }
    

    【讨论】:

    • 感谢您的回答。我进行了您建议的更改,但出现了类似的错误: * 出了什么问题:配置根项目“AwesomeProject”时出现问题。 > 无法解析配置“:classpath”的所有工件。 > 无法解析 com.android.tools.build:gradle:3.0.1。要求:项目:> 无法解析 com.android.tools.build:gradle:3.0.1。 > 无法获取资源“dl.google.com/dl/android/maven2/com/android/tools/build/gradle/…”。
    • @eliastg 您必须按照我所说的在“build.gradle”文件中更改版本。你做到了吗?
    【解决方案2】:

    问题是由我的位置引起的。我不得不为此使用隧道。在那一刻,我在这里创建了一个 SSH 帐户 https://www.dynamicssh.com/create-ssh

    1. 使用 SSH 凭据可以设置本地隧道。我用的是Linux,所以可以用这个命令设置隧道。

      $ ssh -D 1337 -q -C -N youruser@yourserver.something

    更多细节在这里:https://ma.ttias.be/socks-proxy-linux-ssh-bypass-content-filters/

    在 Windows 中,我认为可以使用名为 Bitvise SSH 的工具。

    1. 在终端上为 localhost:1337 定义变量 https_proxyhttp_proxy (端口是您在上一步中设置隧道的端口。)这是使用终端中的隧道。

    2. 然后在设置了 https_proxyhttp_proxy 的同一终端中运行“react-native run-android”。

    感谢所有回答的人。

    最好的问候。

    【讨论】:

    • 是的,dl.google.com 在某些国家/地区被屏蔽!
    • 我正在使用 VPN,但我不断收到错误消息。有什么具体的代理吗?
    • 在那一刻,我想我使用了这里的帐户:dynamicssh.com/create-ssh 然后我使用这些凭据创建了一个本地端口转发,命令类似于:ssh -v -N -D localhost: 1090 theuser@ssh-ipdyna-wathever.com 有了这个,你可以在终端中设置 http_proxy 和 https_proxy。我希望这会有所帮助。
    • 你能解释一下吗?更改目录后,所有现有项目都出现相同的错误。
    • @IshaqKamran 我已经添加了解决方案的更多细节。希望对你有帮助。
    【解决方案3】:

    尝试删除项目中的所有 node_modules 文件夹,然后重新构建。

    我遇到了这个问题,每次我尝试在我的依赖项中指定它需要的 gradle 版本时,我都会收到一个单独的错误,告诉我我的 gradle 版本太低。这是由于node_modules 中的一些 android 库需要不同的 gradle 版本。从头开始重建 node_modules 应该会同步它们。

    【讨论】:

      【解决方案4】:

      当我的互联网关闭时发生在我身上。值得检查一次。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-07-28
        • 1970-01-01
        • 2023-03-17
        • 1970-01-01
        • 1970-01-01
        • 2021-11-01
        • 2021-06-04
        • 1970-01-01
        相关资源
        最近更新 更多