React Native:找不到com.android.tools.build:gradle:2.2.3

问题描述 投票:8回答:2

我正在使用本机做一个Android应用程序,这是我得到的错误:


    FAILURE: Build failed with an exception.

    * What went wrong:
    A problem occurred configuring project ':react-native-fetch-blob'.
    > Could not resolve all artifacts for configuration ':react-native-fetch-blob:classpath'.
       > Could not find com.android.tools.build:gradle:2.2.3.
         Searched in the following locations:
             https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom
             https://jcenter.bintray.com/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar
         Required by:
             project :react-native-fetch-blob

我也收到以下警告:


    > Configure project :app 
    WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
    It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
    WARNING: The specified Android SDK Build Tools version (26.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
    Android SDK Build Tools 28.0.3 will be used.
    To suppress this warning, remove "buildToolsVersion '26.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)
    registerResGeneratingTask is deprecated, use registerGeneratedResFolders(FileCollection)

    > Configure project :react-native-android-location-services-dialog-box 
    WARNING: Configuration 'compile' is obsolete and has been replaced with 'implementation' and 'api'.
    It will be removed at the end of 2018. For more information see: http://d.android.com/r/tools/update-dependency-configurations.html
    WARNING: The specified Android SDK Build Tools version (25.0.2) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
    Android SDK Build Tools 28.0.3 will be used.
    To suppress this warning, remove "buildToolsVersion '25.0.2'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.

这是我的build.gradle文件:


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

    buildscript {
        repositories {
            google()
            jcenter()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:3.2.1'

            // NOTE: Do not place your application dependencies here; they belong
            // in the individual module build.gradle files
            classpath 'com.google.gms:google-services:3.0.0'
        }
    }

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

            // jitpack repo is necessary to fetch ucrop dependency
            maven { url "https://jitpack.io" }
        }
    }

这是我的gradle包装器分发URL:

distributionUrl = HTTPS://services.gradle.org/distributions/gradle-4.6-all.zip

我尝试更改不同存储库的顺序,但仍然得到相同的错误。

android react-native gradle build.gradle gradlew
2个回答
5
投票

似乎从jcenter存储库中删除了com.android.tools.build:gradle:2.2.3。

尝试将此代码添加到顶级build.gradle文件中:

subprojects {project ->
    if (project.name.contains('react-native-fetch-blob')) {
        buildscript {
            repositories {
                maven { url "https://dl.bintray.com/android/android-tools/"  }
            }    
        }
    }
}

1
投票

正如google issuetracker:https://issuetracker.google.com/issues/120759347#comment44所见的解决方法

查看错误日志:

  • 出了什么问题:配置项目':react-native-fetch-blob'时出现问题。无法解析配置':react-native-fetch-blob:classpath'的所有工件。找不到com.android.tools.build:gradle:2.2.3。

您仍在为您的项目:react-native-fetch-blob搜索AGP 2.2.3。

对于使用Android Gradle Plugin较低版本的React Native或CordovaLib项目,例如2.2.3,您可以尝试用以下google()样式替换maven,并添加android工具解决方法。因此,修改build.gradlebuildscripts的顶级allprojects文件,如下所示:

buildscripts {
    repositories {

        // below is the workaround for android tools 
        maven {
            artifactUrls "https://dl.bintray.com/android/android-tools/"
            url "https://jcenter.bintray.com"
        }
        maven {
            url "https://maven.google.com"
        }

        // ... 
        jcenter()

    }
}

allprojects {
    repositories {

        // below is the workaround for android tools 
        maven {
            artifactUrls "https://dl.bintray.com/android/android-tools/"
            url "https://jcenter.bintray.com"
        }
        maven {
            url "https://maven.google.com"
        }

        // ... 
        jcenter()

    }
}

清理项目,然后执行新的同步。

  • 尝试“文件” - >“使缓存无效/重新启动...”
  • 尝试清理项目根目录下的.gradle.idea目录。

见以下参考文献:


对于警告:

警告:配置'compile'已过时,已被'implementation'和'api'取代。

因为您使用的是AGP(Android Gradle Plugin 3.2.1),所以构建配置compile已更改为implementationapi。只需用compileimplementation替换所有的api就会让这个警告消失。请参阅:https://developer.android.com/studio/build/dependencies#dependency_configurations了解更多详情。

警告:指定的Android SDK Build Tools版本(25.0.2)将被忽略,因为它低于Android Gradle Plugin 3.2.1的最低支持版本(28.0.3)。将使用Android SDK Build Tools 28.0.3。要取消此警告,请从build.gradle文件中删除“buildToolsVersion '25 .0.2'”,因为每个版本的Android Gradle Plugin现在都有一个默认版本的构建工具。

此警告仅供您参考,您可以忽略它或从buildToolsVersion '25.0.2'文件中删除build.gradle以禁止此警告。

© www.soinside.com 2019 - 2024. All rights reserved.