47

Recently I have updated my Android Studio to latest version from Latest Android Studio Canary Build: 2.0 Preview

After updating to the new version, my current working directory stop working at all. Every single time when I am trying to clean and build a project they will give me an error like this

Blockquote 'Error:Could not find com.android.tools.build:gradle:2.0.0-alpha2. Searched in the following locations: file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/2.0.0-alpha2/gradle-2.0.0-alpha2.pom file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/2.0.0-alpha2/gradle-2.0.0-alpha2.jar https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-alpha2/gradle-2.0.0-alpha2.pom https://repo1.maven.org/maven2/com/android/tools/build/gradle/2.0.0-alpha2/gradle-2.0.0-alpha2.jar Required by: :android 3:unspecified'

Anyone have an idea how to solve this problem. Thanks in advance.

UPDATE: I am using a Mac machine and installation directory look like

Android Studio Installation Directory

Swapnil Sonar
  • 2,232
  • 2
  • 29
  • 42

9 Answers9

97

Apparently the build tools have been moved from maven to jcenter so you need to change the code from:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
    }
}

to this

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.0.0-alpha2'
    }
}

More details on the changes:

Android Tools Project Site http://tools.android.com/recent

Android Developer Tools community https://plus.google.com/communities/114791428968349268860/stream/7f20992b-7d9a-4309-9d94-6fbe08f0ad6e

Dan-Claudiu Gavril
  • 1,206
  • 9
  • 6
  • 2
    In addition sometimes the newest build tools are not available immediately after announcements on jcenter repository so AndroidStudio can not use them. Solution in this case is to go back to previous version for a few hours/days til new tools are on jcenter. It just happened to me with alpha8 which is announced few hours ago. Back to alpha7 and voila! :) – Ewoks Jan 28 '16 at 14:21
8

In the main build.gradle file, add jcenter() as main repo, just like that :

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Remove other repositories or make sure jcenter is the first one.

NitroG42
  • 5,336
  • 2
  • 28
  • 32
2

On my side travis build failed with error message "Could not find com.android.tools.build:gradle:3.0.1".

After addeing google() as additional repository the problem was gone.

buildscript {
    repositories {
        jcenter()
        google()

My local build did not fail because i had installed before "com.android.tools.build:gradle:3.0.1" with anddroid-sdk-manager

k3b
  • 14,517
  • 7
  • 53
  • 85
1
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

repositories block should be in buildscript. 
Sunshine
  • 387
  • 3
  • 9
0

Check to see if gradle 2.0.0-alpha1 is available on your system. Look in your android/tools/build/gradle folder. In my case, despite the confusing message "This project is using a preview version of the Gradle plugin (2.0.0-alpha2) and a newer version is available (2.0.0-alpha2) You can update to 2.0.0-alpha2." the version in my folder was 2.0.0-alpha1, and changing my build.gradle to: classpath 'com.android.tools.build:gradle:2.0.0-alpha1' fixed my build problem.

jrisch
  • 132
  • 1
  • 9
  • Thanks, @jrisch. I have attached the screenshot of a directory. Can you please next step to process? – Swapnil Sonar Dec 08 '15 at 14:29
  • I'm not familiar with the Mac, but what is under your m2repository/com/android/tools/build/gradle structure? In my case I had 2.0.0-alpha1 and so changed the build.gradle as above. – jrisch Dec 08 '15 at 19:52
0

I removed the newest folder gradle-4.1-all in C:\Users\YOUR_USER_NAME\ .gradle\wrapper\dists\ and then I created a new project in Android Studio and the following message disappeared:

"Gradle sync failed: Could not find com.android.tools.build: Gradle: 3.0.0-beta6. "

Veneet Reddy
  • 2,707
  • 1
  • 24
  • 40
gloslasu
  • 1
  • 2
0
buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.3'
        classpath 'com.google.gms:google-services:3.0.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "https://maven.google.com" }
        maven { url "https://jitpack.io" }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
bakan
  • 1
0

I have tried something like

platfoms > android > cordova >lib > builders > Gradlebuilder.js

Downloaded zip and given path

var distributionUrl = process.env['CORDOVA_ANDROID_GRADLE_DISTRIBUTION_URL'] || 'file\:///C:/MyPC/Documents/softwares/gradle-2.14.1-all.zip';

and linking path is

allprojects {
    repositories {
        mavenLocal()

        google()
        jcenter()
         maven{url "http://jcenter.bintray.com"}
    }
}

It worked for me.

  • this is for Ionic developers *
praveenpds
  • 2,936
  • 5
  • 26
  • 43
-1

This seems to be a very long issue(years on the making)...most of the hints are about settings and gradle scripts. After a few days of digging around and backing from BumbleBee to 3.4.2 I kept on getting the same issue no matter what I tried. In the end the gradle on line URLs are blocked for my location due to network ... so easy for Google to say check the access is proper and not keep us blindfolded throwing darts in the dark

becker
  • 351
  • 4
  • 8