Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting "could not find com.android.tools.build:gradle" error?

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.

like image 522
committedandroider Avatar asked Jun 21 '15 01:06

committedandroider


People also ask

How do I fix Gradle issues?

For this, you have to connect your PC to the internet and you have to open your Android studio. After opening your project click on the Sync Project with Gradle files option. This will automatically download the new Gradle files and will fix the issue which is caused by the Gradle files.

Why is my Gradle build failing?

If gradle --version works, but all of your builds fail with the same error, it is possible there is a problem with one of your Gradle build configuration scripts. You can verify the problem is with Gradle scripts by running gradle help which executes configuration scripts, but no Gradle tasks.

What is Gradle build in Android?

Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.


2 Answers

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,

like image 67
n4h0y Avatar answered Oct 12 '22 01:10

n4h0y


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()
}
like image 21
Frank Feng Avatar answered Oct 12 '22 01:10

Frank Feng