Why am I getting “could not find com.android.tools

2019-03-17 15:47发布

问题:

This is based off my last question as well.

Following this tutorial, I cloned the project into my machine and am trying to get the project to build properly.

In the process of fixing the error I got in my last question, I encountered a new error.
This is the section of the build script I am trying to fix/edit

buildscript {
     repositories {
         mavenCentral()
         mavenLocal()
         maven { url 'https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/' }
      }
      dependencies {
            classpath 'de.richsource.gradle.plugins:gwt-gradle-plugin:0.3'
            classpath 'com.android.tools.build:gradle:1.2.3'
      }
 }

Following the instructions on how to check Gradle version, I checked mine and saw that I was running Gradle version 2.2.1. Based off that, I changed

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

to

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

However after changing that build script code, and attempting to rebuild my project, I get the above mentioned error(full stack trace below)

    Error:Could not find com.android.tools.build:gradle:2.2.1.
Searched in the following locations:
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    file:/C:/Program Files/Android/Android Studio/gradle/m2repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
    file:/C:/Users/chris/.m2/repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    file:/C:/Users/chris/.m2/repository/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
    https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.pom
    https://github.com/steffenschaefer/gwt-gradle-plugin/raw/maven-repo/com/android/tools/build/gradle/2.2.1/gradle-2.2.1.jar
Required by:
    :theplanethatcouldntflygood:unspecified

Does anyone know why I am getting this error or how to fix this? It doesn't make sense for me to point the Java compiler(classpath) at a Gradle Version that I am not even using.

回答1:

You are confusing between android gradle plugin and gradle version.

This classpath 'com.android.tools.build:gradle:1.2.3' is a gradle plugin for Android and as of this time, 1.2.3 is the latest.

The gradle version itself is in gradle-wrapper.properties file. 2.4 is the latest version,



回答2:

you can find last version in this address :
repo1.maven.org/maven2/com/android/tools/build/gradle
jcenter.bintray.com/com/android/tools/build/gradle

buildscript {
repositories {
    maven { url "https://jcenter.bintray.com" }
    maven { url "http://repo1.maven.org/maven2" }
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.0'
}
}

allprojects {
repositories {
    maven { url "https://jitpack.io" }
    maven { url "https://jcenter.bintray.com" }
    maven { url "http://repo1.maven.org/maven2" }
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}


回答3:

Per @Hamidreza's answer, check the maven and jcenter repos. Indeed jcenter (currently) has newer tools than maven.

So in the top-level build.gradle file, change "mavenCentral" to "jcenter" like this

repositories {
    //mavenCentral()
    jcenter()
}


回答4:

I fixed this exact issue by upgrading my version of Android Studio. I was receiving an error Could not find com.android.tools.build:gradle:2.2.0, and was running a 2.1.x version of Studio at the time.

A simple upgrade to 2.2.2 immediately fixed my issue. Hope this can help somebody!



回答5:

If you're behind a proxy, make sure Android Studio is set up for that. It does NOT assume system proxy settings.

My copy of Studio + Gradle wasn't set up to go through the proxy, and as a result it was giving me this error. Would've been nice to get a clear "hey buddy, I can't hit the web", but I got this error instead.