【问题标题】:React-Native-Could not resolve all files for configuration ':classpath'. Could not find com.android.tools.build:gradle:3.4.1React-Native-无法解析配置 ':classpath' 的所有文件。找不到 com.android.tools.build:gradle:3.4.1
【发布时间】:2019-03-06 13:54:13
【问题描述】:

我尝试了this solution on StackOverflow,但没有成功。

我正在使用 Ubuntu 18.04 LTS、Android-Studio-3、Java-1.8、 Gradle-3.4.1.

Github-repo link 我的项目。 我正在构建 React-Native App,在 npm run eject 之后,我无法运行 npm run android

我能够在弹出应用程序之前运行project 但是当我运行npm run android时出现错误,

(base) gd@gd10:~/Desktop/react-native/demo_app$ npm run android

> @ android /home/gd/Desktop/react-native/demo_app
> react-native run-android

Scanning folders for symlinks in /home/gd/Desktop/react-native/demo_app/node_modules (9ms)
JS server already running.
Building and installing the app on the device (cd android && ./gradlew installDebug)...
Download https://jcenter.bintray.com/de/undercouch/gradle-download-task/3.1.2/gradle-do
wnload-task-3.1.2.pom
Download https://jcenter.bintray.com/org/apache/httpcomponents/httpcore/4.4.4/httpcore-
4.4.4.pom
Download https://jcenter.bintray.com/org/apache/httpcomponents/httpcomponents-core/4.4.
4/httpcomponents-core-4.4.4.pom

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'goods_seller'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find com.android.tools.build:gradle:3.4.1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar
     Required by:
         project :
   > Could not find com.android.tools.build:gradle:3.4.1.
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
         https://jcenter.bintray.com/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.jar
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.1.pom
         https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.4.1/gradle-3.4.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 31s
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

虽然我使用sudo apt-get install gradle安装了gradle,但它无法构建gradle,并且找不到gradle。

使用标志 --stactrace 运行时,它给出相同的输出,

gradle -v 输出为

(base) gd@gd10:~/Desktop/react-native/demo_app$ gradle -v

------------------------------------------------------------
Gradle 3.4.1
------------------------------------------------------------

Build time:   2012-12-21 00:00:00 UTC
Revision:     none

Groovy:       2.4.15
Ant:          Apache Ant(TM) version 1.10.3 compiled on July 19 2018
JVM:          1.8.0_201 (Oracle Corporation 25.201-b09)
OS:           Linux 4.15.0-45-generic amd64

(base) gd@gd10:~/Desktop/react-native/demo_app$ 

demo_app/android/build.gradle 文件是

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

buildscript {
    ext {
        buildToolsVersion = "27.0.3"
        minSdkVersion = 16
        compileSdkVersion = 24
        targetSdkVersion = 26
        supportLibVersion = "27.1.1"
    }
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.4.1'

        classpath 'com.android.tools.build:gradle:2.2.2'
        classpath 'de.undercouch:gradle-download-task:3.1.2'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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


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

编辑 1:

cod-e-rection回复后,

我把代码改成了

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

然后在运行npm run android之后, 它给出了错误,

* What went wrong:
A problem occurred evaluating project ':app'.
> Failed to apply plugin [id 'com.android.application']
   > Minimum supported Gradle version is 4.10.1. Current version is 4.4. If using the gradle wrapper, try editing the distributionUrl in /home/gd/Desktop/react-native/demo_app/android/gradle/wrapper/gradle-wrapper.properties to gradle-4.10.1-all.zip

【问题讨论】:

  • 我觉得应该是classpath 'com.android.tools.build:gradle:3.3.2'或者和当前Android Studio版本号一样

标签: android react-native android-gradle-plugin build.gradle react-native-android


【解决方案1】:

您的Could not find com.android.tools.build:gradle:3.4.1. 问题似乎可以通过将版本代码3.4.1 更改为3.3.2 来解决。

存在另一个问题,因为在3.3.2 gradle 版本中,您必须使用最低 gradle 分发版本4.10.1。解决这个打开的gradle-wrapper.properties文件并使用这一行来

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

替换之前的内容。

【讨论】:

  • 欢迎。很高兴为您提供帮助。
【解决方案2】:

最新的android gradle版本是:

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

您可以在以下地址找到文档link .因此,您必须将其从 classpath 'com.android.tools.build:gradle:3.4.1' 更改为:classpath 'com.android.tools.build:gradle:3.3.2',它将被修复。

【讨论】:

  • 感谢@cod-e-rection,它没有用。尝试此答案后,我更新了问题。
【解决方案3】:

首先,在android/gradle/wrapper/gradle-wrapper.properties 中将distributionUrl 更改为:

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

然后,在android/build.gradle 中将 gradle 类路径更改为:

classpath 'com.android.tools.build:gradle:3.3.0'

【讨论】:

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