React Native FAILURE: Build failed with an exception. Could not resolve ':classpath'. Could not find com.android.tools.build:gradle:3.0.1

本秂侑毒 提交于 2019-11-30 16:43:06

问题


When I make the command "react-native run-android" then it happened:

FAILURE: Build failed with an exception.

  • What went wrong: A problem occurred configuring root project 'AsomeProject'.

    Could not resolve all files for configuration ':classpath'. Could not find com.android.tools.build:gradle:3.0.1. Searched in the following locations: 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

screenshot:


回答1:


I had the same problem, I tried Manoj Prabhakar's solution but I fixed adding the google() repository to the buildscript block in the project level build.gradle

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



回答2:


I added google() and mavenlocal() to the buildscript

buildscript {
    repositories {
        google()
        mavenLocal()
        jcenter()
    }
    ....
}



回答3:


Jcenter does not have Gradle 3.0.1.

It is available in Google's maven repository. here

You should add google() to allprojects in your project level build.gradle

Do this:

In your react native project, Navigate to -> android -> build.gradle.

add google() to allproject repository like this:

This should fix your problem.

Edit 1: replace google() with this

maven {
            url "https://maven.google.com/"
}  



回答4:


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

buildscript {
    repositories {
        jcenter()
        google()
    }
    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()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}



回答5:


buildscript {
    repositories {
        google() // I had to put this before jcenter(). If I put jcenter() first it fails when running react-native run-android
        jcenter()
    }
}

To be clear though, if i put jcenter() first in buildscript, I could still get a successful build within Android Studio. Running react-native run-android however was failing until I put google() in front of jcenter(). After that everything was smooth as butter.




回答6:


So,for me this fixed problem,add google() to repositories

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

then from terminal navigate to your project and run

 cd android && gradlew clean

then inside your project run

 react-native run-android 



回答7:


try changing the class path in your build.gradle file from

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

to

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


来源:https://stackoverflow.com/questions/47455411/react-native-failure-build-failed-with-an-exception-could-not-resolve-classp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!