首页 > 解决方案 > 找不到 com.android.tools.build:gradle:4.1.3。在 Android Studio 中升级 gradle 后

问题描述

React native 0.64 app 从 4.0.x升级Android studio到 4.1.3 后,我接受了将 gradle 升级到 4.1.3 的建议,并按照说明进行升级。但是 React Native 应用程序重建会引发错误:

Could not find com.android.tools.build:gradle:4.1.3.
Searched in the following locations:
  - https://jcenter.bintray.com/com/android/tools/build/gradle/4.1.3/gradle-4.1.3.pom

点击以上https://jcenter.binatray.com/com/...登陆页面Forbidden。是错误的原因吗?

我还将 gradle 版本gradle-wrapper.properties从 6.7 更改为 6.8.3:

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

在 中build.gradle,还有:

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

        google()
        jcenter()
        maven { url 'https://www.jitpack.io' }
        maven { url 'https://maven.google.com'
                name 'Google'
        } 
    }

同步项目抛出相同的错误。

更新:build.gradle

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

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 29
        targetSdkVersion = 29
        ndkVersion = "20.1.5948944"
    }
    repositories {
        google()
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath('com.android.tools.build:gradle:4.1.3')
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

        jcenter()
        maven { url 'https://www.jitpack.io' }
        maven { url 'https://maven.google.com' } //for react-native-image-crop-picker
        mavenCentral()
    }
}

标签: androidgradle

解决方案


推荐阅读