56

I've just pulled down an Android project from git, and Android Studio is giving me the following error whenever I attempt to open it;

Error:Could not find com.android.tools.build:gradle:2.2.0-alpha6.
Searched in the following locations:
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.pom
    https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.jar
    https://maven.fabric.io/public/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.pom
    https://maven.fabric.io/public/com/android/tools/build/gradle/2.2.0-alpha6/gradle-2.2.0-alpha6.jar
Required by:
    newApp_Android:app:unspecified

I've installed Gradle locally, and set up environment paths via System.

Under Project Structure/Project, the following setup is in use;

Gradle Version : 2.10
Android Plugin Version : 2.2.0-alpha6
Android Plugin Repository : jcenter
Default Library Repository : jcenter

Could anyone point me in the right direction on this?

Eoghan
  • 1,720
  • 2
  • 17
  • 35
  • 1
    Those urls didn't search JCenter, it looks like. https://bintray.com/android/android-tools/com.android.tools.build.gradle – OneCricketeer Aug 01 '16 at 15:00

7 Answers7

187

This is because the build process is unable to find the dependency in Maven repository. Add jcenter() along with mavenCentral() in your project level build.gradle file.

buildscript {
    repositories {
        mavenCentral()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.0'
    }
}
Bhavit S. Sengar
  • 8,794
  • 6
  • 24
  • 34
sembozdemir
  • 4,137
  • 3
  • 21
  • 30
  • 8
    Thanks, worked great for me, without replacing mavenCentral(), but just adding jcenter(). This made it unnecessary to go back to the old version of Gradle as is suggested in the accepted answer. – luben Sep 23 '16 at 20:08
  • 2
    You'll likely see performance increases in Android Studio if you remove `mavenCentral()` and only keep `jcenter()` for all dependencies in `build.gradle` - see https://code.google.com/p/android/issues/detail?id=72061. Note for project dependencies you may need to keep `mavenCentral()` if you have dependency artifacts not hosted on JCenter. – Sean Barbeau Sep 26 '16 at 16:37
  • 1
    should I remove mavenCentral? – Arnold Roa Dec 31 '16 at 16:36
  • Could you explain why this works and not mavenCentral( ) – sofs1 Jan 01 '17 at 12:37
  • 1
    @ArnoldRoa yes, you can remove mavenCentral() – sembozdemir Jan 26 '17 at 15:15
  • @user3705478 you can see this link for more details: https://blog.bintray.com/2015/02/09/android-studio-migration-from-maven-central-to-jcenter/ – sembozdemir Jan 26 '17 at 15:15
  • @Bhavit S. Sengar thank you for improving description. However, I am not sure that you need mavenCentral() for project level build.gradle file. – sembozdemir Mar 03 '17 at 22:24
9

So I had a similar error while I was trying to build ionic2 project for android. This happened after android studio updated gradle during its updates.

Error: cmd: Command failed with exit code 1 Error output:

FAILURE: Build failed with an exception.

I read the above answers which pointed to update a 'build.gradle' file but turns out there were multiple files with that name in the project. What worked for me (and hopefully helpful to whoever is working on angular2/ionic2 project and having this issue) is updating the build.gradle file at

[rootOfPorject]/platforms/android/CordovaLib/build.gradle

This file was missing the jcenter() entry and now the repository part looks like this and works like a charm.

repositories {
    jcenter()
    mavenCentral()
}

Hope this saves time for someone else.

EDIT: As @rcerecedar mentioned, you might also need to add jcenter() in the following file as well.

[rootOfPorject]/platforms/android/build.gradle

In this file you should check its present in buildscript -> repositories and also optionally in allprojects -> repositories

Hassan
  • 1,002
  • 15
  • 21
  • 1
    Thnaks a lot. It helped me, but, in the end, I had to insert the jcenter() line in BOTH files, the "main" build.gradle and, the one in Cordovalib. – rcerecedar Mar 05 '17 at 16:43
  • Thanks @rcerecedar I have updated my answer to include this information too. – Hassan Mar 07 '17 at 08:06
4

1.Goto "C:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle"

2.See the Latest folder name , i.e "2.2.3" , Copy It.

3.Go to build.gradle(Module:yourapp) file ,

Place here:

buildscript {
repositories {
    mavenCentral()
}
dependencies {
    classpath 'com.android.tools.build:gradle:2.2.3'
}
geekydhaval
  • 178
  • 1
  • 12
1

If you have firewall configured in your PC,try the following in gradle.properties.

systemProp.https.proxyHost=<proxyHostName>
systemProp.https.proxyPort=8080
systemProp.https.proxyUser=<user id>
systemProp.https.proxyPassword=<password>
systemProp.https.nonProxyHosts=www.google.com|localhost
1

What worked for me was i did exactly what "geekydhaval" said, thanks again for that but I went back to the dependencies { classpath 'com.android.tools.build:gradle:2.3.0' } and change from 2.3.2 to 2.3.0 and the build completed successfully.

Matt Brown
  • 31
  • 4
  • This is really a comment, not an answer. With a bit more rep, [you will be able to post comments](//stackoverflow.com/privileges/comment). For the moment, please stick to concrete questions and answers which require no clarification from the author. – anonymous2 May 12 '17 at 18:39
  • Thanks. but always give answers here. No other stuffs. :) – geekydhaval Jun 15 '17 at 17:57
0

Replace the gradle:2.2.0-alpha6 to gradle:2.2.0-alpha3.
If this doesn't work replace it to gradle:2.2.0-alpha2.

Nir Duan
  • 6,164
  • 4
  • 24
  • 38
0

As gradle is updating the previous version will be replaced with new version so we have to change the gradle version in code as it would be referring to previous version and will show error like this

Could not resolve all dependencies for configuration ':classpath'. Could not find com.android.tools.build:gradle:2.2.3. Searched in the following locations: file:/home/ubuntu/.m2/repository/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom file:/home/ubuntu/.m2/repository/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.pom https://oss.sonatype.org/content/repositories/snapshots/com/android/tools/build/gradle/2.2.3/gradle-2.2.3.jar Required by: :: Open file

The solution to this is that we add the repository in the build.gradle file like

buildscript {
repositories {
    mavenCentral()
    google()
    jcenter()
}

OR

GOTO the File Explorer and search

C:\Program Files\Android\Android Studio\gradle\m2repository\com\android\tools\build\gradle

and see the Gradle name with latest version like

Gradle 2.2.0
Gradle 3.2.1
Gradle 2.1.0

and select the latest version like 3.2.1 and paste it in the build.gradle file in dependencies section like

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'}